From f96734023bc6f782ba35f2f5caa86e8f2868e9dc Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 9 Nov 2000 23:54:00 +0000 Subject: [PATCH] hunting down memory corruption --- panda/src/audio/test_audio.cxx | 11 ++-- panda/src/audiotraits/audio_load_mp3.cxx | 66 ++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/panda/src/audio/test_audio.cxx b/panda/src/audio/test_audio.cxx index 4da205a8ec..97ba0644c7 100644 --- a/panda/src/audio/test_audio.cxx +++ b/panda/src/audio/test_audio.cxx @@ -11,15 +11,16 @@ int main(int argc, char* argv[]) { - // if (! AudioPool::verify_sample("test.wav")) { - // audio_cat->fatal() << "could not locate 'test.wav'" << endl; - // exit(-1); - // } + for (int i=1; ifatal() << "could not locate '" << argv[i] << "'" << endl; + exit(-1); + } + if (! AudioPool::verify_sound("test.mp3")) { audio_cat->fatal() << "could not locate 'test.mp3'" << endl; exit(-1); } - // AudioSample* sample = AudioPool::load_sample("test.wav"); AudioSound* sample = AudioPool::load_sound("test.mp3"); audio_cat->info() << "test.wav is " << sample->length() << " sec long" << endl; diff --git a/panda/src/audiotraits/audio_load_mp3.cxx b/panda/src/audiotraits/audio_load_mp3.cxx index cdad0fe1eb..da76585f88 100644 --- a/panda/src/audiotraits/audio_load_mp3.cxx +++ b/panda/src/audiotraits/audio_load_mp3.cxx @@ -107,8 +107,6 @@ static void set_synth_functions(struct frame* fr) { } static void initialize(void) { - if (initialized) - return; // make sure params say what we want param.quiet = TRUE; param.force_stereo = 1; @@ -117,6 +115,10 @@ static void initialize(void) { memset(&mp, 0, sizeof(struct mpstr)); audio_info_struct_init(&ai); audio_capabilities(&ai); + + if (initialized) + return; + set_synth_functions(&fr); make_decode_tables(param.outscale); init_layer2(); /* inits also shared tables with layer1 */ @@ -129,6 +131,36 @@ static void initialize(void) { initialized = true; } +/* +class BufferStuff { +private: + typedef vector Buffer; + typedef vector Buffers; + Buffers _bufs; +public: + BufferStuff(void) {} + ~BufferStuff(void) { + } + void add(unsigned char* b, unsigned long l) { + _bufs.push_back(Buffer(b, b+l)); + } + unsigned long length(void) const { + unsigned long ret = 0; + for (Buffers::const_iterator i=_bufs.begin(); i!=_bufs.end(); ++i) + ret += (*i).size(); + return ret; + } + void output(unsigned char* b) { + for (Buffers::const_iterator i=_bufs.begin(); i!=_bufs.end(); ++i) + for (Buffer::const_iterator j=(*i).begin(); j!=(*i).end(); ++j) + *(b++) = (*j); + } +}; + +static BufferStuff* my_buf; +*/ + +/* class BufferPart { private: unsigned char* _ptr; @@ -166,6 +198,9 @@ public: static BufferPart* my_buf_head; static BufferPart* my_buf_curr; +*/ + +string my_buf; extern "C" { int audio_open(struct audio_info_struct* ai) { @@ -214,11 +249,22 @@ int audio_get_formats(struct audio_info_struct* ai) { int audio_play_samples(struct audio_info_struct* ai, unsigned char* buf, int len) { + /* if (my_buf_head == (BufferPart*)0L) { my_buf_head = my_buf_curr = new BufferPart(buf, len); } else { my_buf_curr = my_buf_curr->add(buf, len); } + */ + /* + if (my_buf == (BufferStuff*)0L) + my_buf = new BufferStuff; + my_buf->add(buf, len); + */ + string tmp; + for (int i=0; ilength(); *buf = new byte[slen]; my_buf_head->output(*buf); delete my_buf_head; + */ + /* + slen = my_buf->length(); + *buf = new byte[slen]; + my_buf->output(*buf); + delete my_buf; + my_buf = (BufferStuff*)0L; + */ + slen = my_buf.size(); + *buf = new byte[slen]; + memcpy(*buf, my_buf.data(), slen); } #ifdef AUDIO_USE_MIKMOD