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:
parent
366fdcdfbb
commit
7942339dee
|
@ -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; ix<fPlayFile->CountTracks(); 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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -121,6 +121,7 @@ private:
|
|||
BMediaTrack *fPlayTrack;
|
||||
int64 fPlayLimit;
|
||||
int64 fPlayFrame;
|
||||
int64 fPlayFrames;
|
||||
|
||||
media_node fAudioMixerNode;
|
||||
|
||||
|
|
|
@ -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; i<rightIndex; 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue