Browse Source

Begin to support waveform display during capture.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
e7c2ac9ecd
5 changed files with 72 additions and 14 deletions
  1. +7
    -4
      Timeline/Audio_File_SF.C
  2. +14
    -10
      Timeline/Record_DS.C
  3. +3
    -0
      Timeline/Region.H
  4. +41
    -0
      Timeline/Track_Header.C
  5. +7
    -0
      Timeline/Track_Header.H

+ 7
- 4
Timeline/Audio_File_SF.C View File

@@ -84,7 +84,7 @@ Audio_File_SF::create ( const char *filename, nframes_t samplerate, int channels
/* FIXME: bogus */
si.format = SF_FORMAT_WAV | SF_FORMAT_PCM_24 | SF_ENDIAN_CPU;

if ( ! ( out = sf_open( filename, SFM_WRITE, &si ) ) )
if ( ! ( out = sf_open( filename, SFM_RDWR, &si ) ) )
{
printf( "couldn't create soundfile.\n" );
return NULL;
@@ -143,7 +143,7 @@ Audio_File_SF::seek ( nframes_t offset )
{
if ( offset != _current_read )
{
sf_seek( _in, _current_read = offset, SEEK_SET );
sf_seek( _in, _current_read = offset, SEEK_SET | SFM_READ );
}
}

@@ -196,7 +196,6 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end
return len;
}


/** write /nframes/ from /buf/ to soundfile. Should be interleaved for
* the appropriate number of channels */
nframes_t
@@ -204,5 +203,9 @@ Audio_File_SF::write ( sample_t *buf, nframes_t nframes )
{
_peak_writer->write( buf, nframes );

return sf_writef_float( _in, buf, nframes );
nframes_t l = sf_writef_float( _in, buf, nframes );

_length += l;

return l;
}

+ 14
- 10
Timeline/Record_DS.C View File

@@ -41,7 +41,7 @@ Record_DS::write_block ( sample_t *buf, nframes_t nframes )

// timeline->wrlock();

_af->write( buf, nframes );
_th->write( buf, nframes );

// track()->record( buf, _frame, nframes, channels() );

@@ -141,9 +141,11 @@ Record_DS::start ( nframes_t frame )
return;
}

_af = Audio_File_SF::create( "testing.wav", 48000, channels(), "Wav/24" );
_frame = frame;

_th->record( frame );

run();

_recording = true;
@@ -165,21 +167,23 @@ Record_DS::stop ( nframes_t frame )

/* FIXME: flush buffers here? */

char *name = strdup( _af->name() );
delete _af;
_af = NULL;
/* char *name = strdup( _af->name() ); */
/* delete _af; */
/* _af = NULL; */

Audio_File *af = Audio_File::from_file( name );
/* Audio_File *af = Audio_File::from_file( name ); */

if ( ! af )
printf( "impossible!\n" );
/* if ( ! af ) */
/* printf( "impossible!\n" ); */

new Region( af, track(), _frame );
/* new Region( af, track(), _frame ); */

track()->redraw();
/* track()->redraw(); */

_recording = false;

_th->stop( frame );

printf( "recording finished\n" );
}



+ 3
- 0
Timeline/Region.H View File

@@ -101,6 +101,7 @@ private:
Fade _fade_in;
Fade _fade_out;

friend class Track_Header; /* for _clip */
protected:

const char *class_name ( void ) { return "Region"; }
@@ -231,6 +232,8 @@ class Region : public Region_Base

bool current ( void ) const { return this == belowmouse(); }

friend class Track_Header; /* for _clip in Track_Header::write() */

public:




+ 41
- 0
Timeline/Track_Header.C View File

@@ -333,3 +333,44 @@ Track_Header::seek ( nframes_t frame )
if ( playback_ds )
return playback_ds->seek( frame );
}



/* FIXME: what about theading issues with this region/audiofile being
accessible from the UI thread? Need locking? */

#include "Region.H"

/* THREAD: IO */
/** create capture region and prepare to record */
void
Track_Header::record ( nframes_t nframes )
{
assert( _capture == NULL );

/* FIXME: hack */
Audio_File *af = Audio_File_SF::create( "testing.wav", 48000, input.size(), "Wav/24" );

_capture = new Region( af, track(), nframes );

/* FIXME: wrong place for this */
_capture->_r->end = 0;
}

/* THREAD: IO */
/** write a block to the (already opened) capture file */
void
Track_Header::write ( sample_t *buf, nframes_t nframes )
{
_capture->_r->end +=_capture->_clip->write( buf, nframes );

/* FIXME: too much? */
_capture->redraw();
}

/* THREAD: IO */
void
Track_Header::stop ( nframes_t nframes )
{
_capture = NULL;
}

+ 7
- 0
Timeline/Track_Header.H View File

@@ -32,6 +32,7 @@

// #include "Port.H"

/* TODO: rename this to Audio_Track_Header or something since it's audio specific. */

#include <vector>
using std::vector;
@@ -65,6 +66,8 @@ private:

Track *_track;

Region *_capture; /* capture region */

public:

Fl_Input * name_field;
@@ -274,5 +277,9 @@ public:
/* Engine */
nframes_t process ( nframes_t nframes );
void seek ( nframes_t frame );
void record ( nframes_t nframes );
void write ( sample_t *buf, nframes_t nframes );
void stop ( nframes_t nframes );

};
#endif

Loading…
Cancel
Save