now count frames only once

release files and tracks


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13460 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2005-07-05 19:04:59 +00:00
parent 366fdcdfbb
commit 7942339dee
3 changed files with 34 additions and 11 deletions
+20 -4
View File
@@ -104,6 +104,7 @@ RecorderWindow::RecorderWindow() :
fSoundList(NULL), fSoundList(NULL),
fPlayFile(NULL), fPlayFile(NULL),
fPlayTrack(NULL), fPlayTrack(NULL),
fPlayFrames(0),
fSavePanel(NULL), fSavePanel(NULL),
fInitCheck(B_OK) fInitCheck(B_OK)
{ {
@@ -139,6 +140,14 @@ RecorderWindow::~RecorderWindow()
if (fPlayer) { if (fPlayer) {
delete fPlayer; delete fPlayer;
} }
if (fPlayTrack && fPlayFile)
fPlayFile->ReleaseTrack(fPlayTrack);
if (fPlayFile)
delete fPlayFile;
fPlayTrack = NULL;
fPlayFile = NULL;
// Clean up items in list view. // Clean up items in list view.
if (fSoundList) { if (fSoundList) {
fSoundList->DeselectAll(); fSoundList->DeselectAll();
@@ -567,7 +576,7 @@ RecorderWindow::MessageReceived(BMessage * message)
} }
if (message->FindInt64("right", &right) == B_OK) { if (message->FindInt64("right", &right) == B_OK) {
if (fPlayTrack) 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); fScopeView->SetRightTime(right);
} }
if (message->FindInt64("left", &left) == B_OK) { if (message->FindInt64("left", &left) == B_OK) {
@@ -679,7 +688,7 @@ RecorderWindow::Play(BMessage * message)
return; 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()); fPlayTrack->SeekToTime(fTrackSlider->MainTime());
fPlayFrame = fPlayTrack->CurrentFrame(); fPlayFrame = fPlayTrack->CurrentFrame();
@@ -1037,6 +1046,13 @@ RecorderWindow::UpdatePlayFile()
return; return;
} }
if (fPlayTrack && fPlayFile)
fPlayFile->ReleaseTrack(fPlayTrack);
if (fPlayFile)
delete fPlayFile;
fPlayTrack = NULL;
fPlayFile = NULL;
status_t err; status_t err;
BEntry& entry = pItem->Entry(); BEntry& entry = pItem->Entry();
entry_ref ref; entry_ref ref;
@@ -1048,8 +1064,6 @@ RecorderWindow::UpdatePlayFile()
return; return;
} }
ASSERT(fPlayTrack == NULL);
for (int ix=0; ix<fPlayFile->CountTracks(); ix++) { for (int ix=0; ix<fPlayFile->CountTracks(); ix++) {
BMediaTrack * track = fPlayFile->TrackAt(ix); BMediaTrack * track = fPlayFile->TrackAt(ix);
fPlayFormat.type = B_MEDIA_RAW_AUDIO; fPlayFormat.type = B_MEDIA_RAW_AUDIO;
@@ -1111,6 +1125,8 @@ RecorderWindow::UpdatePlayFile()
fScopeView->SetRightTime(fTrackSlider->RightTime()); fScopeView->SetRightTime(fTrackSlider->RightTime());
fScopeView->SetLeftTime(fTrackSlider->LeftTime()); fScopeView->SetLeftTime(fTrackSlider->LeftTime());
fScopeView->RenderTrack(fPlayTrack, fPlayFormat); fScopeView->RenderTrack(fPlayTrack, fPlayFormat);
fPlayFrames = fPlayTrack->CountFrames();
} }
+1
View File
@@ -121,6 +121,7 @@ private:
BMediaTrack *fPlayTrack; BMediaTrack *fPlayTrack;
int64 fPlayLimit; int64 fPlayLimit;
int64 fPlayFrame; int64 fPlayFrame;
int64 fPlayFrames;
media_node fAudioMixerNode; media_node fAudioMixerNode;
+12 -6
View File
@@ -12,9 +12,15 @@
#include "DrawingTidbits.h" #include "DrawingTidbits.h"
#include "ScopeView.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) 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), fThreadId(-1),
fBitmap(NULL), fBitmap(NULL),
fIsRendering(false), fIsRendering(false),
@@ -125,12 +131,12 @@ ScopeView::RenderLoop()
int32 sumCount = 0; int32 sumCount = 0;
fMediaTrack->SeekToFrame(&frames); fMediaTrack->SeekToFrame(&frames);
printf("begin computing\n"); TRACE("begin computing\n");
int32 previewIndex = 0; int32 previewIndex = 0;
while (fMediaTrack->ReadFrames(samples, &frames) == B_OK) { while (fMediaTrack->ReadFrames(samples, &frames) == B_OK) {
//printf("reading block\n"); //TRACE("reading block\n");
framesIndex = 0; framesIndex = 0;
while (framesIndex < frames) { while (framesIndex < frames) {
@@ -145,7 +151,7 @@ ScopeView::RenderLoop()
} }
if (sumCount >= totalFrames/20000) { 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); fPreview[previewIndex++] = (int32)(sum / 2 /(totalFrames/20000) / 32767.0 * fHeight / 2 + fHeight / 2);
sumCount = 0; sumCount = 0;
sum = 0; sum = 0;
@@ -155,7 +161,7 @@ ScopeView::RenderLoop()
} }
printf("finished computing\n"); TRACE("finished computing\n");
/* rendering */ /* rendering */
RenderBitmap(); RenderBitmap();
@@ -262,7 +268,7 @@ ScopeView::RenderBitmap()
for (int32 i = leftIndex; i<rightIndex; i++) { for (int32 i = leftIndex; i<rightIndex; i++) {
BPoint point((i - leftIndex) * width / (rightIndex - leftIndex), fPreview[i]); BPoint point((i - leftIndex) * width / (rightIndex - leftIndex), fPreview[i]);
//printf("point x %f y %f\n", point.x, point.y); //TRACE("point x %f y %f\n", point.x, point.y);
fBitmapView->StrokeLine(point, point); fBitmapView->StrokeLine(point, point);
} }