From: Pierre-Jean L. <pj-...@us...> - 2005-10-25 19:45:52
|
Update of /cvsroot/wired/wired/src/sequencer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8876/src/sequencer Modified Files: Sequencer.cpp Sequencer.h Log Message: Some changes on exporting WaveFile Index: Sequencer.h =================================================================== RCS file: /cvsroot/wired/wired/src/sequencer/Sequencer.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Sequencer.h 17 Oct 2005 17:58:32 -0000 1.10 --- Sequencer.h 25 Oct 2005 19:45:38 -0000 1.11 *************** *** 33,39 **** --- 33,41 ---- void DeleteBuffer() { + if (Buffer[0]) delete Buffer[0]; if (Buffer[1]) delete Buffer[1]; + if (Buffer) delete Buffer; } *************** *** 108,111 **** --- 110,115 ---- void ProcessCurrentMidiEvents(Track *T, MidiPattern *p); void WriteExport(); + void AllocExportBuffer(unsigned int NbChannels); + void FreeExportBuffer(unsigned int NbChannels); double StartAudioPos; list<MidiEvent *> MidiEvents; *************** *** 114,117 **** --- 118,122 ---- float **AllocBuf1; float **AllocBuf2; + float **ExportBuf; WriteWaveFile *ExportWave; WaveFile *PlayWave; Index: Sequencer.cpp =================================================================== RCS file: /cvsroot/wired/wired/src/sequencer/Sequencer.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Sequencer.cpp 17 Oct 2005 17:58:32 -0000 1.32 --- Sequencer.cpp 25 Oct 2005 19:45:38 -0000 1.33 *************** *** 21,25 **** #include "../samplerate/WiredSampleRate.h" - Sequencer::Sequencer() : wxThread(), BPM(96), SigNumerator(4), SigDenominator(4), Loop(false), --- 21,24 ---- *************** *** 40,43 **** --- 39,44 ---- CalcSpeed(); + ExportBuf = NULL; + SampleRateConverter = NULL; } *************** *** 89,92 **** --- 90,96 ---- while (ok) { + + if (TestDestroy() == true) + break; /* - Traitement des messages MIDI recus */ MidiMutex.Lock(); *************** *** 270,275 **** --- 274,282 ---- if ((*RacksTrack)->CurrentBuffer) { + if ((*RacksTrack)->CurrentBuffer[0]) delete (*RacksTrack)->CurrentBuffer[0]; + if ((*RacksTrack)->CurrentBuffer[1]) delete (*RacksTrack)->CurrentBuffer[1]; + if ((*RacksTrack)->CurrentBuffer) delete (*RacksTrack)->CurrentBuffer; (*RacksTrack)->CurrentBuffer = 0x0; *************** *** 300,303 **** --- 307,311 ---- if (PlayWavePos >= PlayWave->GetNumberOfFrames()) { + if (PlayWave) delete PlayWave; PlayWave = 0x0; *************** *** 338,346 **** } ExtraBufs.clear(); - if (TestDestroy() == true) - break; } cout << "[SEQ] Thread finished !" << endl; ! return (Wait()); } --- 346,353 ---- } ExtraBufs.clear(); } cout << "[SEQ] Thread finished !" << endl; ! //return (Wait()); ! return NULL; } *************** *** 437,441 **** Track* track = Tracks.back(); Tracks.pop_back(); ! delete track; SeqMutex.Unlock(); } --- 444,449 ---- Track* track = Tracks.back(); Tracks.pop_back(); ! if (track) ! delete track; SeqMutex.Unlock(); } *************** *** 772,778 **** t->Patterns.erase(k); SeqMutex.Unlock(); ! ! delete (p); ! break; } --- 780,785 ---- t->Patterns.erase(k); SeqMutex.Unlock(); ! if (p) ! delete (p); break; } *************** *** 828,835 **** } bool Sequencer::ExportToWave(string &filename) { ! Seq->Stop(); ! if (!SampleRateConverter) delete SampleRateConverter; SampleRateConverter = new WiredSampleRate; --- 835,872 ---- } + void Sequencer::AllocExportBuffer(unsigned int NbChannels) + { + unsigned int Current; + + if (NbChannels > 0) + { + ExportBuf = new float *[NbChannels]; + for (Current = 0; Current < NbChannels; Current++) + ExportBuf[Current] = new float [Audio->SamplesPerBuffer]; + } + } + + void Sequencer::FreeExportBuffer(unsigned int NbChannels) + { + if (ExportBuf) + { + unsigned int Current; + + if (NbChannels > 0) + { + + for (Current = 0; Current < NbChannels; Current++) + if (ExportBuf[Current]) + delete ExportBuf[Current]; + delete [] ExportBuf; + } + ExportBuf = NULL; + } + } + bool Sequencer::ExportToWave(string &filename) { ! Seq->Stop(); ! if (SampleRateConverter) delete SampleRateConverter; SampleRateConverter = new WiredSampleRate; *************** *** 840,846 **** Info.SamplesPerBuffer = Audio->SamplesPerBuffer; SampleRateConverter->Init(&Info); ! if (SampleRateConverter->SaveFile(filename, 2, Audio->SamplesPerBuffer)) { SeqMutex.Lock(); SetCurrentPos(BeginLoopPos); Exporting = true; --- 877,885 ---- Info.SamplesPerBuffer = Audio->SamplesPerBuffer; SampleRateConverter->Init(&Info); ! if (SampleRateConverter->SaveFile(filename, 2, Audio->SamplesPerBuffer, true)) { SeqMutex.Lock(); + FreeExportBuffer(2); + AllocExportBuffer(2); SetCurrentPos(BeginLoopPos); Exporting = true; *************** *** 853,873 **** return false; ! try ! { ! ExportWave = new WriteWaveFile(filename, (int)Audio->SampleRate, 2, ! SF_FORMAT_PCM_16); ! SetCurrentPos(BeginLoopPos); ! ! SeqMutex.Lock(); ! Exporting = true; ! SeqMutex.Unlock(); ! ! Play(); ! } ! catch (...) ! { ! cout << "[SEQUENCER] Could not create export file" << endl; // FIXME error dialog box ! } ! return false; } --- 892,912 ---- return false; ! // try ! // { ! // ExportWave = new WriteWaveFile(filename, (int)Audio->SampleRate, 2, ! // SF_FORMAT_PCM_16); ! // SetCurrentPos(BeginLoopPos); ! // ! // SeqMutex.Lock(); ! // Exporting = true; ! // SeqMutex.Unlock(); ! // ! // Play(); ! // } ! // catch (...) ! // { ! // cout << "[SEQUENCER] Could not create export file" << endl; // FIXME error dialog box ! // } ! // return false; } *************** *** 882,895 **** delete SampleRateConverter; SampleRateConverter = NULL; } SeqMutex.Unlock(); return; ! if (ExportWave) ! { ! delete ExportWave; ! ExportWave = 0x0; ! } ! SeqMutex.Unlock(); } --- 921,935 ---- delete SampleRateConverter; SampleRateConverter = NULL; + FreeExportBuffer(2); } SeqMutex.Unlock(); return; ! // if (ExportWave) ! // { ! // delete ExportWave; ! // ExportWave = 0x0; ! // } ! // SeqMutex.Unlock(); } *************** *** 898,902 **** if (SampleRateConverter) { - cout << "Write Export" << endl; // for (i = 0, j = 0; i < Audio->SamplesPerBuffer; j++) --- 938,941 ---- *************** *** 913,938 **** // SampleRateConverter->WriteToFile((unsigned long) Audio->SamplesPerBuffer, AllocBuf1, 2); //SeqMutex.Lock(); ! memcpy(AllocBuf1[0], Mix->OutputLeft, Audio->SamplesPerBuffer); ! memcpy(AllocBuf1[1], Mix->OutputRight, Audio->SamplesPerBuffer); ! SampleRateConverter->WriteToFile((unsigned long) Audio->SamplesPerBuffer, AllocBuf1, 2); cout << "Write Export ended" << endl; //SeqMutex.Unlock(); } return; ! ! long i, j, chan; ! ! for (i = 0, j = 0; i < Audio->SamplesPerBuffer; j++) ! { ! AllocBuf1[0][i++] = Mix->OutputLeft[j]; ! AllocBuf1[0][i++] = Mix->OutputRight[j]; ! } ! ExportWave->WriteFloat(AllocBuf1[0], Audio->SamplesPerBuffer); ! for (i = 0; i < Audio->SamplesPerBuffer; j++) ! { ! AllocBuf1[0][i++] = Mix->OutputLeft[j]; ! AllocBuf1[0][i++] = Mix->OutputRight[j]; ! } ! ExportWave->WriteFloat(AllocBuf1[0], Audio->SamplesPerBuffer); } --- 952,984 ---- // SampleRateConverter->WriteToFile((unsigned long) Audio->SamplesPerBuffer, AllocBuf1, 2); //SeqMutex.Lock(); ! memcpy(ExportBuf[0], Mix->OutputLeft, Audio->SamplesPerBuffer); ! memcpy(ExportBuf[1], Mix->OutputRight, Audio->SamplesPerBuffer); ! long j; ! ! for (j = 0; j < Audio->SamplesPerBuffer; j++) ! { ! ExportBuf[0][j] = Mix->OutputLeft[j]; ! ExportBuf[1][j] = Mix->OutputRight[j]; ! } ! SampleRateConverter->WriteToFile((unsigned long) Audio->SamplesPerBuffer, ExportBuf, 2); cout << "Write Export ended" << endl; //SeqMutex.Unlock(); } return; ! ! // long i, j, chan; ! // ! // for (i = 0, j = 0; i < Audio->SamplesPerBuffer; j++) ! // { ! // AllocBuf1[0][i++] = Mix->OutputLeft[j]; ! // AllocBuf1[0][i++] = Mix->OutputRight[j]; ! // } ! // ExportWave->WriteFloat(AllocBuf1[0], Audio->SamplesPerBuffer); ! // for (i = 0; i < Audio->SamplesPerBuffer; j++) ! // { ! // AllocBuf1[0][i++] = Mix->OutputLeft[j]; ! // AllocBuf1[0][i++] = Mix->OutputRight[j]; ! // } ! // ExportWave->WriteFloat(AllocBuf1[0], Audio->SamplesPerBuffer); } |