Size Waveforms to clip length.
This commit is contained in:
parent
05854badd9
commit
1684805c63
|
@ -0,0 +1,98 @@
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
||||||
|
/* */
|
||||||
|
/* This program is free software; you can redistribute it and/or modify it */
|
||||||
|
/* under the terms of the GNU General Public License as published by the */
|
||||||
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
||||||
|
/* option) any later version. */
|
||||||
|
/* */
|
||||||
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
||||||
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
||||||
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
||||||
|
/* more details. */
|
||||||
|
/* */
|
||||||
|
/* You should have received a copy of the GNU General Public License along */
|
||||||
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
||||||
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||||
|
/*******************************************************************************/
|
||||||
|
|
||||||
|
#include "Clip.H"
|
||||||
|
#include "Timeline.H"
|
||||||
|
|
||||||
|
#include <sndfile.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
Clip::Clip ( const char *filename ) : _peaks( this )
|
||||||
|
{
|
||||||
|
_filename = filename;
|
||||||
|
|
||||||
|
SNDFILE *in;
|
||||||
|
SF_INFO si;
|
||||||
|
|
||||||
|
memset( &si, 0, sizeof( si ) );
|
||||||
|
|
||||||
|
in = sf_open( filename, SFM_READ, &si );
|
||||||
|
|
||||||
|
if ( si.channels != 1 )
|
||||||
|
printf( "error: incompatible format" );
|
||||||
|
|
||||||
|
if ( si.samplerate != timeline.sample_rate )
|
||||||
|
printf( "error: samplerate mismatch!\n" );
|
||||||
|
|
||||||
|
_length = si.frames;
|
||||||
|
|
||||||
|
sf_close( in );
|
||||||
|
|
||||||
|
_peaks.open( filename );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Clip::open ( void )
|
||||||
|
{
|
||||||
|
SF_INFO si;
|
||||||
|
|
||||||
|
memset( &si, 0, sizeof( si ) );
|
||||||
|
|
||||||
|
if ( ! ( _in = sf_open( _filename, SFM_READ, &si ) ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Clip::close ( void )
|
||||||
|
{
|
||||||
|
sf_close( _in );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Clip::seek ( nframes_t offset )
|
||||||
|
{
|
||||||
|
sf_seek( _in, offset, SEEK_SET );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nframes_t
|
||||||
|
Clip::read ( sample_t *buf, nframes_t len )
|
||||||
|
{
|
||||||
|
return sf_read_float ( _in, buf, len );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** read samples from /start/ to /end/ into /buf/ */
|
||||||
|
nframes_t
|
||||||
|
Clip::read ( sample_t *buf, nframes_t start, nframes_t end )
|
||||||
|
{
|
||||||
|
open();
|
||||||
|
|
||||||
|
seek( start );
|
||||||
|
|
||||||
|
nframes_t len = read( buf, end - start );
|
||||||
|
|
||||||
|
close();
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
23
Clip.H
23
Clip.H
|
@ -20,9 +20,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef unsigned long nframes_t;
|
typedef unsigned long nframes_t;
|
||||||
|
typedef float sample_t;
|
||||||
|
|
||||||
#include "Peaks.H"
|
#include "Peaks.H"
|
||||||
|
|
||||||
|
#include <sndfile.h>
|
||||||
|
|
||||||
class Clip
|
class Clip
|
||||||
{
|
{
|
||||||
const char *_filename;
|
const char *_filename;
|
||||||
|
@ -31,20 +34,20 @@ class Clip
|
||||||
|
|
||||||
nframes_t _length; /* length of clip in samples */
|
nframes_t _length; /* length of clip in samples */
|
||||||
|
|
||||||
|
SNDFILE *_in;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Clip ( const char *filename ) : _peaks( this )
|
Clip ( const char *filename );
|
||||||
{
|
|
||||||
_filename = filename;
|
|
||||||
|
|
||||||
// FIXME: open file
|
|
||||||
|
|
||||||
_peaks.open( filename );
|
|
||||||
}
|
|
||||||
|
|
||||||
Peaks const * peaks ( void ) { return &_peaks; }
|
Peaks const * peaks ( void ) { return &_peaks; }
|
||||||
|
|
||||||
const char *name ( void ) { return _filename; }
|
const char *name ( void ) { return _filename; }
|
||||||
|
|
||||||
nframes_t length ( void ) { return _length; }
|
nframes_t length ( void ) { return _length; }
|
||||||
|
|
||||||
|
bool open ( void );
|
||||||
|
void close ( void );
|
||||||
|
void seek ( nframes_t offset );
|
||||||
|
nframes_t read ( sample_t *buf, nframes_t len );
|
||||||
|
nframes_t read ( sample_t *buf, nframes_t start, nframes_t end );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ CXXFLAGS=-ggdb -Wall -O0
|
||||||
LIBS=-lsndfile `fltk-config --ldflags`
|
LIBS=-lsndfile `fltk-config --ldflags`
|
||||||
# CXXFLAGS=`fltk-config -cxxflags`
|
# CXXFLAGS=`fltk-config -cxxflags`
|
||||||
|
|
||||||
SRCS= Waveform.C Region.C Peaks.C main.C
|
SRCS= Clip.C Waveform.C Region.C Peaks.C main.C
|
||||||
|
|
||||||
OBJS=$(SRCS:.C=.o)
|
OBJS=$(SRCS:.C=.o)
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,10 @@ public:
|
||||||
_scale = 1;
|
_scale = 1;
|
||||||
label( _clip->name() );
|
label( _clip->name() );
|
||||||
|
|
||||||
|
_start = 0;
|
||||||
_end = _clip->length();
|
_end = _clip->length();
|
||||||
|
|
||||||
|
size( timeline.ts_to_x( _end ), h() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Waveform ( const Waveform & rhs ) : Fl_Widget( rhs.x(), rhs.y(), rhs.w(), rhs.h(), rhs.label() )
|
Waveform ( const Waveform & rhs ) : Fl_Widget( rhs.x(), rhs.y(), rhs.w(), rhs.h(), rhs.label() )
|
||||||
|
|
Loading…
Reference in New Issue