游戏开发论坛

 找回密码
 立即注册
搜索
楼主: 春风扫冬风

爱国的进来。。。。

[复制链接]

28

主题

685

帖子

703

积分

高级会员

Rank: 4

积分
703
发表于 2005-3-19 20:09:00 | 显示全部楼层

Re:爱国的进来。。。。

/*
  THIS IS WRITTEN FOR CHAD AUSTIN FOR AUDIERE
  By Jacky Chong

  In short, this is some wierd **** I wrote up because Chad
  didn't want to touch this. Also, I have no idea what I've
  done as well to get it work as well.

  I've since done a bunch of work on it.    -Chad
*/

#include <string.h>
#include "input_mp3.h"
#include "utility.h"
#include "debug.h"


// The number of MP3 frame that are processed at a time.  If this value
// is smaller, the decoder should take less memory.  However, it may
// skip on corrupt MP3s.
static const int FRAME_COUNT = 10;


namespace audiere {


  class MyLoader : public Soundinputstream {
  public:
    MyLoader(FilePtr file) {
      m_file = file;
      m_eof = false;
    }

    int getbytedirect() {
      u8 b;
      if (m_file->read(&b, 1) == 1) {
        return b;
      } else {
        seterrorcode(SOUND_ERROR_FILEREADFAIL);
        m_eof = true;
        return -1;
      }
    }

    bool _readbuffer(char* buffer, int size) {
      if (m_file->read(buffer, size) == size) {
        return true;
      } else {
        seterrorcode(SOUND_ERROR_FILEREADFAIL);
        m_eof = true;
        return false;
      }
    }

    bool eof() {
      return m_eof;
    }

    int getblock(char* buffer, int size) {
      int read = m_file->read(buffer, size);
      if (read != size) {
        m_eof = true;
      }
      return read;
    }

    int getsize() {
      int pos = m_file->tell();
      m_file->seek(0, File::END);
      int size = m_file->tell();
      m_file->seek(pos, File::BEGIN);
      return size;
    }

    void setposition(int pos) {
      m_file->seek(pos, File::BEGIN);
      m_eof = false;
    }

    int getposition() {
      return m_file->tell();
    }

  private:
    FilePtr m_file;
    bool m_eof;
  };


  MP3InputStream::MP3InputStream() {
    m_file = 0;

    m_channel_count = 2;
    m_sample_rate = 44100;
    m_sample_format = SF_S16;

    m_decoder = 0;
    m_loader = 0;
  }

  
  MP3InputStream::~MP3InputStream() {
    delete m_decoder;
    delete m_loader;
  }


  bool
  MP3InputStream::initialize(FilePtr file) {
    m_file = file;
    m_loader = new MyLoader(file);
    m_decoder = new Mpegtoraw(m_loader, this);

    m_decoder->initialize();

    // this should call setsoundtype with the format of the stream
    if (!m_decoder->run(FRAME_COUNT)) {
      return false;
    }

    return true;
  }


  void
  MP3InputStream::getFormat(
    int& channel_count,
    int& sample_rate,
    SampleFormat& sample_format)
  {
    channel_count = m_channel_count;
    sample_rate = m_sample_rate;
    sample_format = m_sample_format;
  }

  
  int
  MP3InputStream::doRead(int frame_count, void* samples) {
    ADR_GUARD("MP3InputStream::doRead");

    const int frame_size = m_channel_count * GetSampleSize(m_sample_format);

    int frames_read = 0;
    u8* out = (u8*)samples;

    while (frames_read < frame_count) {

      // no more samples?  ask the MP3 for more
      if (m_buffer.getSize() < frame_size) {
        if (!m_decoder->run(FRAME_COUNT)) {
          // done decoding?
          return frames_read;
        }

        // if the buffer is still empty, we are done
        if (m_buffer.getSize() < frame_size) {
          return frames_read;
        }
      }

      const int frames_left = frame_count - frames_read;
      const int frames_to_read = std::min(
        frames_left,
        m_buffer.getSize() / frame_size);

      m_buffer.read(out, frames_to_read * frame_size);
      out += frames_to_read * frame_size;
      frames_read += frames_to_read;
    }

    return frames_read;
  }


  void
  MP3InputStream::reset() {
    ADR_GUARD("MP3InputStream::reset");

    m_file->seek(0, File::BEGIN);

    m_buffer.clear();
    m_channel_count = 2;
    m_sample_rate = 44100;
    m_sample_format = SF_S16;

    delete m_decoder;
    delete m_loader;

    m_loader = new MyLoader(m_file.get());
    m_decoder = new Mpegtoraw(m_loader, this);

    m_decoder->initialize();

    // this should call setsoundtype with the format of the stream
    if (!m_decoder->run(FRAME_COUNT)) {
      return;
    }
  }


  bool
  MP3InputStream::setsoundtype(int stereo, int samplesize, int speed) {
    m_channel_count = (stereo ? 2 : 1);
    m_sample_rate = speed;

    if (samplesize == 8) {
      m_sample_format = SF_U8;
    } else if (samplesize == 16) {
      m_sample_format = SF_S16;
    } else {
      return false;
    }

    return true;
  }


  bool
  MP3InputStream::putblock(void* buffer, int size) {
    m_buffer.write(buffer, size);
    return true;
  }

}

28

主题

685

帖子

703

积分

高级会员

Rank: 4

积分
703
发表于 2005-3-19 20:09:00 | 显示全部楼层

Re:爱国的进来。。。。

#ifndef INPUT_MP3_H
#define INPUT_MP3_H

#include <mpegsound.h>
#include "audiere.h"
#include "basic_source.h"
#include "types.h"
#include "utility.h"

namespace audiere {

  class MP3InputStream : public BasicSource, public Soundplayer {
  public:
    MP3InputStream();
    ~MP3InputStream();

    bool initialize(FilePtr file);

    void ADR_CALL getFormat(
      int& channel_count,
      int& sample_rate,
      SampleFormat& sample_format);
    int doRead(int frame_count, void* samples);
    void ADR_CALL reset();

    bool setsoundtype(int stereo, int samplesize, int speed);
    bool putblock(void *buffer,int size);

  private:
    FilePtr m_file;

    // from format chunk
    int m_channel_count;
    int m_sample_rate;
    SampleFormat m_sample_format;

    Mpegtoraw* m_decoder;
    Soundinputstream* m_loader;
   
    QueueBuffer m_buffer;
  };

}

#endif

63

主题

871

帖子

891

积分

高级会员

Rank: 4

积分
891
QQ
发表于 2005-3-19 20:10:00 | 显示全部楼层

Re:爱国的进来。。。。

啊!!!!!!!!!!!!!!!!!!!!!!!!!!

3

主题

20

帖子

20

积分

注册会员

Rank: 2

积分
20
发表于 2005-3-19 20:12:00 | 显示全部楼层

Re: 爱国的进来。。。。

楼主的企图岂会因这样一个贴子而得逞?这样也太小看我们中国人了嘛.
正府在小日本这么公然挑衅下依然保持镇定自若,很能说明正府的能力吧?做为人民怎么就连这一点点气能忍不住呢?

46

主题

281

帖子

313

积分

中级会员

Rank: 3Rank: 3

积分
313
QQ
发表于 2005-3-19 20:41:00 | 显示全部楼层

Re:爱国的进来。。。。

给你你也用用用用用用用用不了。。。

139

主题

2005

帖子

2057

积分

金牌会员

Rank: 6Rank: 6

积分
2057
QQ
发表于 2005-3-19 23:45:00 | 显示全部楼层

Re:爱国的进来。。。。

猫咪猛!

4

主题

18

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2005-3-20 08:38:00 | 显示全部楼层

Re:爱国的进来。。。。

Liker:
   呵呵。。谁说我用不了。。。。是拿来学而以。。。。。。
      这是帖最多是开个玩笑而以。。事事当真。。人生得出累啦。。

59

主题

1104

帖子

1199

积分

金牌会员

Rank: 6Rank: 6

积分
1199
发表于 2005-3-20 10:31:00 | 显示全部楼层

Re:爱国的进来。。。。

莫名其妙的帖子,告诉你原理,自己吃不了,难道还真TMD要嚼碎了喂你吃?

9

主题

23

帖子

28

积分

注册会员

Rank: 2

积分
28
发表于 2005-3-20 12:03:00 | 显示全部楼层

Re:爱国的进来。。。。

4

主题

15

帖子

15

积分

新手上路

Rank: 1

积分
15
发表于 2005-3-20 12:52:00 | 显示全部楼层

Re:爱国的进来。。。。

我最不喜欢看别人代码,烦
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-24 23:15

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表