From: <pst...@us...> - 2010-07-17 16:52:59
|
Revision: 802 http://jazzplusplus.svn.sourceforge.net/jazzplusplus/?rev=802&view=rev Author: pstieber Date: 2010-07-17 16:52:53 +0000 (Sat, 17 Jul 2010) Log Message: ----------- 1. Renamed JZSampleSet data members... softsync -> mSoftwareSynchonization ticks_per_minute -> mTicksPerMinute free_buffers -> mFreeBuffers full_buffers -> mFullBuffers driv_buffers -> mDriverBuffers 2. Started adding accessors to JZSampleSet (GetFullBuffers) to prevent the need to friend JZWindowsAudioPlayer, JZAudioPlayer, and JZAlsaAudioPlayer, but mutators are also required. I'll get there eventually. Modified Paths: -------------- trunk/jazz/src/AlsaDriver.cpp trunk/jazz/src/Audio.cpp trunk/jazz/src/Audio.h trunk/jazz/src/mswin/WindowsAudioInterface.cpp Modified: trunk/jazz/src/AlsaDriver.cpp =================================================================== --- trunk/jazz/src/AlsaDriver.cpp 2010-07-17 16:44:35 UTC (rev 801) +++ trunk/jazz/src/AlsaDriver.cpp 2010-07-17 16:52:53 UTC (rev 802) @@ -460,7 +460,7 @@ for (; room > frag_size[PLAYBACK]; room -= frag_size[PLAYBACK]) { - JZAudioBuffer* buf = mSamples.full_buffers.Get(); + JZAudioBuffer* buf = mSamples.GetFullBuffers().Get(); if (buf == 0) { break; Modified: trunk/jazz/src/Audio.cpp =================================================================== --- trunk/jazz/src/Audio.cpp 2010-07-17 16:44:35 UTC (rev 801) +++ trunk/jazz/src/Audio.cpp 2010-07-17 16:52:53 UTC (rev 802) @@ -188,23 +188,21 @@ //***************************************************************************** //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -JZSampleSet::JZSampleSet(long tpm) +JZSampleSet::JZSampleSet(long TicksPerMinute) : mSamplingRate(22050), mChannelCount(1), // Dont change!!! mBitsPerSample(16), - softsync(1), + mSoftwareSynchonization(true), + mTicksPerMinute(TicksPerMinute), mpSamplesDialog(0), mDefaultFileName("noname.spl"), mRecordFileName("noname.wav") { int i; - - ticks_per_minute = tpm; - - for (i = 0; i < BUFCOUNT; i++) + for (i = 0; i < BUFCOUNT; ++i) { buffers[i] = new JZAudioBuffer(0); } @@ -293,7 +291,7 @@ ifstream Is(FileName.c_str()); int Version; - Is >> Version >> mSamplingRate >> mChannelCount >> softsync; + Is >> Version >> mSamplingRate >> mChannelCount >> mSoftwareSynchonization; while (Is) { int key, pan, vol, pitch; @@ -364,7 +362,10 @@ { ofstream Ofs(FileName.c_str()); Ofs - << 1 << ' ' << mSamplingRate << ' ' << mChannelCount << ' ' << softsync + << 1 + << ' ' << mSamplingRate + << ' ' << mChannelCount + << ' ' << mSoftwareSynchonization << endl; for (int i = 0; i < eSampleCount; i++) { @@ -399,21 +400,24 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int JZSampleSet::ResetBuffers(JZEventArray *evnt_arr, long clock, long tpm) +int JZSampleSet::ResetBuffers( + JZEventArray *evnt_arr, + long clock, + long TicksPerMinute) { int i; - free_buffers.Clear(); - full_buffers.Clear(); - driv_buffers.Clear(); + mFreeBuffers.Clear(); + mFullBuffers.Clear(); + mDriverBuffers.Clear(); for (i = 0; i < BUFCOUNT; i++) { - free_buffers.Put(buffers[i]); + mFreeBuffers.Put(buffers[i]); } buffers_written = 0; events = evnt_arr; start_clock = clock; - ticks_per_minute = tpm; + mTicksPerMinute = TicksPerMinute; event_index = 0; bufshorts = BUFSHORTS; mClocksPerBuffer = Samples2Ticks(bufshorts); @@ -443,7 +447,7 @@ // and compute the count of buffers that can be filled int i; - int nfree = free_buffers.Count(); + int nfree = mFreeBuffers.Count(); if (nfree <= 0) { return 0; @@ -469,14 +473,14 @@ // iterate the events and add sounding voices while (event_index < events->nEvents) { - JZEvent *e = events->Events[event_index]; - if (e->GetClock() >= last_clock) + JZEvent* pEvent = events->Events[event_index]; + if (pEvent->GetClock() >= last_clock) { break; } event_index++; - JZKeyOnEvent* pKeyOn = e->IsKeyOn(); + JZKeyOnEvent* pKeyOn = pEvent->IsKeyOn(); if (pKeyOn && num_voices < MAXPOLY) { voices[num_voices++]->Start( @@ -488,7 +492,7 @@ // add remaining sample data to the buffers for (i = 0; i < nfree; i++) { - JZAudioBuffer* buf = free_buffers.Get(); + JZAudioBuffer* buf = mFreeBuffers.Get(); buf->Clear(); long buffer_clock = BufferClock(buffers_written + i); @@ -501,7 +505,7 @@ { voices[k]->AddBuffer(buf->data, buffer_clock, bufshorts); } - full_buffers.Put(buf); + mFullBuffers.Put(buf); } // delete finished voices @@ -530,22 +534,22 @@ { listen_sample = spl; - assert(ticks_per_minute); - ResetBuffers(0, 0, ticks_per_minute); + assert(mTicksPerMinute); + ResetBuffers(0, 0, mTicksPerMinute); voices[0]->Start(spl, 0); - int nfree = free_buffers.Count(); + int nfree = mFreeBuffers.Count(); int sound_buffers = 0; for (int i = 0; i < nfree; i++) { - JZAudioBuffer* buf = free_buffers.Get(); + JZAudioBuffer* buf = mFreeBuffers.Get(); buf->Clear(); if (!voices[0]->Finished()) { voices[0]->AddListen(buf->Data(), fr_smpl, to_smpl, bufshorts); sound_buffers++; } - full_buffers.Put(buf); + mFullBuffers.Put(buf); } buffers_written = nfree; return sound_buffers; @@ -563,19 +567,19 @@ //----------------------------------------------------------------------------- int JZSampleSet::ContinueListen() { - int nfree = free_buffers.Count(); + int nfree = mFreeBuffers.Count(); int sound_buffers = 0; for (int i = 0; i < nfree; i++) { - JZAudioBuffer* buf = free_buffers.Get(); + JZAudioBuffer* buf = mFreeBuffers.Get(); buf->Clear(); if (!voices[0]->Finished()) { voices[0]->AddListen(buf->Data(), -1, -1, bufshorts); sound_buffers++; } - full_buffers.Put(buf); + mFullBuffers.Put(buf); } buffers_written += nfree; return sound_buffers; @@ -583,18 +587,20 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void JZSampleSet::AdjustAudioLength(JZTrack *t, long tpm) +void JZSampleSet::AdjustAudioLength(JZTrack* pTrack, long TicksPerMinute) { - if (!t->GetAudioMode() || !adjust_audio_length) + if (!pTrack->GetAudioMode() || !adjust_audio_length) + { return; + } - ticks_per_minute = tpm; + mTicksPerMinute = TicksPerMinute; - JZEventIterator it(t); - JZEvent *e = it.First(); - while (e) + JZEventIterator it(pTrack); + JZEvent* pEvent = it.First(); + while (pEvent) { - JZKeyOnEvent* pKeyOn = e->IsKeyOn(); + JZKeyOnEvent* pKeyOn = pEvent->IsKeyOn(); if (pKeyOn) { pKeyOn->SetLength( @@ -606,7 +612,7 @@ pKeyOn->SetLength(15); } } - e = it.Next(); + pEvent = it.Next(); } } @@ -728,7 +734,7 @@ enable = gpMidiPlayer->GetAudioEnabled(); stereo = (mSampleSet.GetChannelCount() == 2); - softsync = mSampleSet.GetSoftSync(); + mSoftwareSynchonization = mSampleSet.GetSoftSync(); Add(wxMakeFormBool("Enable Audio", &enable)); Add(wxMakeFormNewLine()); @@ -738,7 +744,7 @@ Add(wxMakeFormNewLine()); Add(wxMakeFormBool("Stereo", &stereo)); Add(wxMakeFormNewLine()); - Add(wxMakeFormBool("Software Midi/Audio Sync", &softsync)); + Add(wxMakeFormBool("Software Midi/Audio Sync", &mSoftwareSynchonization)); #ifdef wx_x Add(wxMakeFormNewLine()); @@ -765,7 +771,7 @@ speed = atol(speedstr); mSampleSet.SetSamplingRate(speed); mSampleSet.SetChannelCount(stereo ? 2 : 1); - mSampleSet.SetSoftSync(softsync); + mSampleSet.SetSoftSync(mSoftwareSynchonization); gpMidiPlayer->SetAudioEnabled(enable); if (gpConfig->GetValue(C_EnableAudio) != enable) @@ -810,7 +816,7 @@ const char *speedstr; bool enable; bool stereo; - bool softsync; + bool mSoftwareSynchonization; bool ossbug1; bool ossbug2; bool duplex_audio; @@ -905,7 +911,10 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -void JZSampleSet::SaveRecordingDlg(long frc, long toc, JZAudioRecordBuffer &buf) +void JZSampleSet::SaveRecordingDlg( + long frc, + long toc, + JZAudioRecordBuffer& buf) { if (frc >= toc) { @@ -990,11 +999,11 @@ pSong->NewUndoBuffer(); #endif JZEventIterator iter(info->mpTrack); - JZEvent *e = iter.Range(frc, toc); - while (e != 0) + JZEvent* pEvent = iter.Range(frc, toc); + while (pEvent != 0) { - track->Kill(e); - e = iter.Next(); + track->Kill(pEvent); + pEvent = iter.Next(); } // add a noteon JZKeyOnEvent* pKeyOn = new JZKeyOnEvent( @@ -1057,8 +1066,11 @@ int end_buffer = end_index / bufsize; int end_length = end_index % bufsize; - // save part of first buffer - os.write((char *)&buf.buffers[start_buffer]->data[start_offs], 2 * start_length); + // Save part of first buffer. + os.write( + (char *)&buf.buffers[start_buffer]->data[start_offs], + 2 * start_length); + // write some complete buffers for (int i = start_buffer + 1; i < end_buffer; i++) os.write((char *)buf.buffers[i]->data, bufsize * 2); Modified: trunk/jazz/src/Audio.h =================================================================== --- trunk/jazz/src/Audio.h 2010-07-17 16:44:35 UTC (rev 801) +++ trunk/jazz/src/Audio.h 2010-07-17 16:52:53 UTC (rev 802) @@ -234,7 +234,7 @@ eSampleCount = 128 }; - JZSampleSet(long ticks_per_minute); + JZSampleSet(long TicksPerMinute); virtual ~JZSampleSet(); @@ -283,15 +283,15 @@ bool GetSoftSync() const { - return softsync; + return mSoftwareSynchonization; } - void SetSoftSync(bool x) + void SetSoftSync(bool SoftwareSynchonization) { - softsync = x; + mSoftwareSynchonization = SoftwareSynchonization; } - int ResetBuffers(JZEventArray *, long start_clock, long ticks_per_minute); + int ResetBuffers(JZEventArray *, long start_clock, long TicksPerMinute); int ResetBufferSize(unsigned int bytes); @@ -303,13 +303,13 @@ return buffers[i]; } - void AdjustAudioLength(JZTrack *t, long ticks_per_minute); + void AdjustAudioLength(JZTrack *t, long TicksPerMinute); long Ticks2Samples(long ticks) const { long spl = (long)( 60.0 * ticks * mSamplingRate * mChannelCount / - (double)ticks_per_minute); + (double)mTicksPerMinute); // Align to the first channel. return spl & -mChannelCount; @@ -318,18 +318,18 @@ double Samples2Ticks(long samples) const { return (double) - samples * ticks_per_minute / 60.0 / mSamplingRate / mChannelCount; + samples * mTicksPerMinute / 60.0 / mSamplingRate / mChannelCount; } // time in millisec long Ticks2Time(long ticks) const { - return (long)(60000.0 * ticks / ticks_per_minute); + return (long)(60000.0 * ticks / mTicksPerMinute); } long Time2Ticks(long time) const { - return (long)((double)time * ticks_per_minute / 60000.0); + return (long)((double)time * mTicksPerMinute / 60000.0); } long Samples2Time(long samples) const @@ -384,6 +384,8 @@ void ClearSampleSet(wxWindow* pParent); + const JZAudioBufferQueue& GetFullBuffers() const; + protected: long SampleSize(long num_samples) @@ -409,12 +411,15 @@ // This must be 16! int mBitsPerSample; - bool softsync; // enable software midi/audio sync + // Indicates if software MIDI/audio synchronization is on. + bool mSoftwareSynchonization; JZSample* mSamples[eSampleCount]; JZSampleFrame* mSampleFrames[eSampleCount]; - long ticks_per_minute; // MIDI sampling rate for audio/midi sync. + // MIDI sampling rate for audio/midi sync. + long mTicksPerMinute; + double mClocksPerBuffer; long start_clock; // when did play start @@ -423,9 +428,9 @@ unsigned int bufbytes; // buffer size in byte unsigned int bufshorts; // buffer size in short JZAudioBuffer *buffers[BUFCOUNT]; // all the audio buffers - JZAudioBufferQueue free_buffers; // to be filled with data - JZAudioBufferQueue full_buffers; // to be played by driver - JZAudioBufferQueue driv_buffers; // actually played by driver + JZAudioBufferQueue mFreeBuffers; // to be filled with data + JZAudioBufferQueue mFullBuffers; // to be played by driver + JZAudioBufferQueue mDriverBuffers; // actually played by driver // return the start clock for i-th free buffer long buffers_written; // for computing buffers clock @@ -454,4 +459,12 @@ JZSample* listen_sample; }; +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +inline +const JZAudioBufferQueue& JZSampleSet::GetFullBuffers() const +{ + return mFullBuffers; +} + #endif // !defined(JZ_AUDIO_H) Modified: trunk/jazz/src/mswin/WindowsAudioInterface.cpp =================================================================== --- trunk/jazz/src/mswin/WindowsAudioInterface.cpp 2010-07-17 16:44:35 UTC (rev 801) +++ trunk/jazz/src/mswin/WindowsAudioInterface.cpp 2010-07-17 16:52:53 UTC (rev 802) @@ -460,8 +460,8 @@ { blocks_played ++; play_buffers_needed ++; - JZAudioBuffer* buf = mSamples.driv_buffers.Get(); - mSamples.free_buffers.Put(buf); + JZAudioBuffer* buf = mSamples.mDriverBuffers.Get(); + mSamples.mFreeBuffers.Put(buf); } if (hinp_open && wMsg == MM_WIM_DATA) { @@ -496,7 +496,7 @@ if (mAudioEnabled && hout_open) { JZAudioBuffer* pAudioBuffer; - while ((pAudioBuffer = mSamples.full_buffers.Get()) != 0) + while ((pAudioBuffer = mSamples.mFullBuffers.Get()) != 0) { if ( waveOutWrite( @@ -504,12 +504,12 @@ pAudioBuffer->hdr, sizeof(WAVEHDR)) == MMSYSERR_NOERROR) { - mSamples.driv_buffers.Put(pAudioBuffer); + mSamples.mDriverBuffers.Put(pAudioBuffer); --play_buffers_needed; } else { - mSamples.full_buffers.UnGet(pAudioBuffer); + mSamples.mFullBuffers.UnGet(pAudioBuffer); break; } } @@ -533,7 +533,7 @@ } // midi time correction - if (mCanSynchronize && mSamples.softsync) + if (mCanSynchronize && mSamples.GetSoftSync()) { MMTIME mmtime; MMRESULT res; @@ -582,7 +582,7 @@ } } - if (mCanSynchronize && mSamples.softsync && !hout_open) + if (mCanSynchronize && mSamples.GetSoftSync() && !hout_open) { // midi time correction MMTIME mmtime; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |