diff --git a/src/apps/soundrecorder/RecorderWindow.cpp b/src/apps/soundrecorder/RecorderWindow.cpp index 3fcb03d669..6ad0c6631a 100644 --- a/src/apps/soundrecorder/RecorderWindow.cpp +++ b/src/apps/soundrecorder/RecorderWindow.cpp @@ -104,6 +104,7 @@ RecorderWindow::RecorderWindow() : fSoundList(NULL), fPlayFile(NULL), fPlayTrack(NULL), + fPlayFrames(0), fSavePanel(NULL), fInitCheck(B_OK) { @@ -139,6 +140,14 @@ RecorderWindow::~RecorderWindow() if (fPlayer) { delete fPlayer; } + + if (fPlayTrack && fPlayFile) + fPlayFile->ReleaseTrack(fPlayTrack); + if (fPlayFile) + delete fPlayFile; + fPlayTrack = NULL; + fPlayFile = NULL; + // Clean up items in list view. if (fSoundList) { fSoundList->DeselectAll(); @@ -567,7 +576,7 @@ RecorderWindow::MessageReceived(BMessage * message) } if (message->FindInt64("right", &right) == B_OK) { if (fPlayTrack) - fPlayLimit = MIN(fPlayTrack->CountFrames(), (off_t)(right * fPlayFormat.u.raw_audio.frame_rate/1000000LL)); + fPlayLimit = MIN(fPlayFrames, (off_t)(right * fPlayFormat.u.raw_audio.frame_rate/1000000LL)); fScopeView->SetRightTime(right); } if (message->FindInt64("left", &left) == B_OK) { @@ -679,7 +688,7 @@ RecorderWindow::Play(BMessage * message) return; } - fPlayLimit = MIN(fPlayTrack->CountFrames(), (off_t)(fTrackSlider->RightTime()*fPlayFormat.u.raw_audio.frame_rate/1000000LL)); + fPlayLimit = MIN(fPlayFrames, (off_t)(fTrackSlider->RightTime()*fPlayFormat.u.raw_audio.frame_rate/1000000LL)); fPlayTrack->SeekToTime(fTrackSlider->MainTime()); fPlayFrame = fPlayTrack->CurrentFrame(); @@ -1036,6 +1045,13 @@ RecorderWindow::UpdatePlayFile() if (! pItem) { return; } + + if (fPlayTrack && fPlayFile) + fPlayFile->ReleaseTrack(fPlayTrack); + if (fPlayFile) + delete fPlayFile; + fPlayTrack = NULL; + fPlayFile = NULL; status_t err; BEntry& entry = pItem->Entry(); @@ -1047,9 +1063,7 @@ RecorderWindow::UpdatePlayFile() delete fPlayFile; return; } - - ASSERT(fPlayTrack == NULL); - + for (int ix=0; ixCountTracks(); ix++) { BMediaTrack * track = fPlayFile->TrackAt(ix); fPlayFormat.type = B_MEDIA_RAW_AUDIO; @@ -1111,6 +1125,8 @@ RecorderWindow::UpdatePlayFile() fScopeView->SetRightTime(fTrackSlider->RightTime()); fScopeView->SetLeftTime(fTrackSlider->LeftTime()); fScopeView->RenderTrack(fPlayTrack, fPlayFormat); + + fPlayFrames = fPlayTrack->CountFrames(); } diff --git a/src/apps/soundrecorder/RecorderWindow.h b/src/apps/soundrecorder/RecorderWindow.h index 143dd2d912..a2beb57d80 100644 --- a/src/apps/soundrecorder/RecorderWindow.h +++ b/src/apps/soundrecorder/RecorderWindow.h @@ -121,6 +121,7 @@ private: BMediaTrack *fPlayTrack; int64 fPlayLimit; int64 fPlayFrame; + int64 fPlayFrames; media_node fAudioMixerNode; diff --git a/src/apps/soundrecorder/ScopeView.cpp b/src/apps/soundrecorder/ScopeView.cpp index a68fdac038..9fd780d6a9 100644 --- a/src/apps/soundrecorder/ScopeView.cpp +++ b/src/apps/soundrecorder/ScopeView.cpp @@ -12,9 +12,15 @@ #include "DrawingTidbits.h" #include "ScopeView.h" +//#define TRACE 1 +#ifdef TRACE +#define TRACE(x) printf(x) +#else +#define TRACE(x) +#endif ScopeView::ScopeView(BRect rect, uint32 resizeFlags) - : BView(rect, "vumeter", resizeFlags, B_WILL_DRAW | B_FRAME_EVENTS), + : BView(rect, "scope", resizeFlags, B_WILL_DRAW | B_FRAME_EVENTS), fThreadId(-1), fBitmap(NULL), fIsRendering(false), @@ -125,12 +131,12 @@ ScopeView::RenderLoop() int32 sumCount = 0; fMediaTrack->SeekToFrame(&frames); - printf("begin computing\n"); + TRACE("begin computing\n"); int32 previewIndex = 0; while (fMediaTrack->ReadFrames(samples, &frames) == B_OK) { - //printf("reading block\n"); + //TRACE("reading block\n"); framesIndex = 0; while (framesIndex < frames) { @@ -145,7 +151,7 @@ ScopeView::RenderLoop() } if (sumCount >= totalFrames/20000) { - //printf("computing block %ld, sumCount %ld\n", previewIndex, sumCount); + //TRACE("computing block %ld, sumCount %ld\n", previewIndex, sumCount); fPreview[previewIndex++] = (int32)(sum / 2 /(totalFrames/20000) / 32767.0 * fHeight / 2 + fHeight / 2); sumCount = 0; sum = 0; @@ -155,7 +161,7 @@ ScopeView::RenderLoop() } - printf("finished computing\n"); + TRACE("finished computing\n"); /* rendering */ RenderBitmap(); @@ -262,7 +268,7 @@ ScopeView::RenderBitmap() for (int32 i = leftIndex; iStrokeLine(point, point); }