14 #ifndef CSL_SoundFile_H
15 #define CSL_SoundFile_H
28 #ifdef CSL_ENUMS // use enumerations or integers?
54 #define kSoundFileRead 0
55 #define kSoundFileWrite 1
56 #define kSoundFileReadWrite 2
59 #define kSoundFileFormatWAV 0
60 #define kSoundFileFormatAIFF 1
61 #define kSoundFileFormatSND 2
62 #define kSoundFileFormatEBICSF 3
63 #define kSoundFileFormatRaw 4
64 #define kSoundFileFormatOther 5
110 static const char *
mimeType(
const char * path);
118 unsigned rate = 44100,
119 unsigned bitDepth = 16)
throw (
CException) = 0;
148 virtual void close() = 0;
155 virtual bool isCached(
unsigned samps);
157 virtual void setPath(
string path);
195 void checkBuffer(
unsigned numChans,
unsigned numFrames);
216 void readFrom(FILE *input);
231 #ifdef USE_SNDFILEBUFFER
237 class SoundFileBuffer :
public Buffer {
244 virtual SampleBuffer samplePtrFor(
unsigned channel,
unsigned offset);
246 virtual SampleBuffer samplePtrFor(
unsigned channel,
unsigned offset,
unsigned maxFrame);
252 virtual void setBuffer(
unsigned bufNum,
SampleBuffer sPtr) {
253 throw LogicError(
"Cannot set pointer to file buffer"); };
254 virtual void setBuffer(
unsigned bufNum,
unsigned offset,
sample samp) {
255 throw LogicError(
"Cannot set pointer to file buffer"); };
268 #ifdef UNDEFINED // this was never completed...
273 SampleFile(
string name,
Abst_SoundFile *file = 0,
int start = 1,
int stop = -1);
281 double ratioForKey(
int desiredMIDI);
282 double ratioForPitch(
int desiredMIDI);
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
UnitGenerator * mReadRate
my playback rate
SeekPosition
Enumeration for seek flags.
SoundFileFormat mFormat
sf format
#define kSoundFileFormatAIFF
virtual void close()=0
close file
unsigned mNumFrames
sample frames
#define CSL_mSndFileFrames
default file cache size = 20 MFrames (~ 2 min)
double mRate
sample rate ratio
bool isActive()
answer if currently active
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
SoundFileMode mMode
r/w mode
static const char * mimeType(const char *path)
Answer the MIME type based on the file name.
WavetableOscillator – Oscillator with a stored wave table that does table look-up. The default wave table is an 8192-sample sine. (perhaps accept a vector of freqs and a multichannel buffer?)
static SoundFileFormat sndfileNameType(const char *path)
Answer the snd file type.
#define kSoundFileRead
Sound file constants.
unsigned cacheSize()
size in frames of cached portion
unsigned mBase
starting frame in file of buffer
void mergeToMono()
average all the channels to mono
virtual void readBufferFromFile(unsigned numFr)=0
#define kSoundFileReadWrite
virtual unsigned seekTo(int position, SeekPosition whence)=0
seek to some position relative to "whence"
virtual void setToEnd()
set to end position
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
virtual void setPath(string path)
set file name path string
Abst_SoundFile * mFile
the file I point into
float mFloatCurrent
current pointer as a float
virtual void initFromSndfile()=0
read SF header
virtual void trigger()
reset to start
#define kSoundFileFormatRaw
#define kSoundFileFormatEBICSF
void setStopRatio(float val)
bool mIsValid
is my file valid?
virtual void openForWrite(SoundFileFormat format=kSoundFileFormatAIFF, unsigned channels=1, unsigned rate=44100, unsigned bitDepth=16)=0
Open a file for writing. Default values are some common format.
Abst_SoundFile(string path, int start=-1, int stop=-1)
Constructor. Values not passed default to null.
#define kSoundFileFormatSND
bool isLooping()
get/set looping state
unsigned mBytesPerSample
the # of bytes per sample
#define kSoundFileFormatOther
unsigned seekTo(int position)
read a buffer from the file (possibly all of it)
float sample
(could be changed to int, or double)
#define kSoundFileFormatWAV
virtual void freeBuffer()
free the file cache
virtual void openForRead(bool load=true)=0
unsigned mNumAlloc
num frames in each buffer
Writeable – a mix-in for buffers and streams that one can write to.
bool readTags()
read the ID3 or other tags. Returns true if able to read them.
bool mIsLooping
am i looping start-stop?
static bool isSndfileName(const char *path)
Answer whether the given name looks like a snd file.
int stopFrame()
get/set stop frame
SoundCue – a pointer to a segment of a sound file.
int mStop
starting/ending frames (or -1 if not used)
virtual void nextBuffer(Buffer &outB)
UGen operations are implemented here copy next buffer from file cache.
virtual SampleBuffer buffer(unsigned bufNum)
Buffer mWavetable
the stored wave form
void setStartRatio(float val)
void setIsLooping(bool tLooping)
bool isValid()
answer if a valid file/buffer
virtual void writeBuffer(Buffer &inB)=0
write a buffer of data into the file
unsigned channels() const
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
virtual void dump()
log snd file props
void setStartSec(float val)
void convertRate(int fromRate, int toRate)
perform sample-rate conversion
void setRate(UnitGenerator &frequency)
set the receiver's playback rate (pitch ratio)
double playbackRate()
playback rate (pitch ratio)
SoundFileMetadata * mProperties
the ID3 tags properties
SoundFileMode mode()
r/w mode
void checkBuffer(unsigned numFrames)
allocate buffer lazily
unsigned sampleSize()
get the bytes-per-sample
virtual bool isCached()
answer if file is loaded into RAM
Here's the abstract sound file reader/writer class, a sample player UGen. The concrete subclasses rep...
float duration() const
duration in frames
unsigned channels() const
accessors
int startFrame()
get/set start frame
Seekable – a mix-in for positionable streams.
float durationInSecs()
number of frames in the sound file
Base class of CSL exceptions (written upper-case). Has a string message.
void setStopSec(float val)