From bebb41262bdc44cd8d4432ddaa7640fa89b242f4 Mon Sep 17 00:00:00 2001 From: Mick Grierson Date: Sat, 7 Apr 2012 11:43:02 +0100 Subject: "added ogg vorbis support also did some minor bug fixes for windows and fixed a bug in stereo sample loading where the files played back a t a funny speed" You *need* to make sure that stb_vorbis.h and stb_vorbis.c are included in your VS2010 or Xcode project if you want vorbis support! --- maximilian.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 11 deletions(-) (limited to 'maximilian.cpp') diff --git a/maximilian.cpp b/maximilian.cpp index eca57a6..fc00f25 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -31,9 +31,19 @@ * */ + #include "maximilian.h" #include "math.h" +/* Maximilian can be configured to load ogg vorbis format files using the +* loadOgg() method. +* Uncomment the following to include Sean Barrett's Ogg Vorbis decoder.*/ + +//#define VORBIS + +#ifdef VORBIS +#include "stb_vorbis.h" +#endif //int channels=2; //int samplerate=44100; @@ -352,6 +362,31 @@ bool maxiSample::load(string fileName, int channel) { return read(); } +bool maxiSample::loadOgg(char *fileName, int channel) { +#ifdef VORBIS + bool result; + result=fileName; + readChannel=channel; + int channelx; + myDataSize = stb_vorbis_decode_filename(fileName, &channelx, &temp); + printf("\nchannels = %d\nlength = %d",channelx,myDataSize); + printf("\n"); + myChannels=(short)channelx; + length=myDataSize; + mySampleRate=44100; + + if (myChannels>1) { + int position=0; + int channel=readChannel; + for (int i=channel;ilength) position=0; @@ -444,7 +484,8 @@ double maxiSample::play() { double maxiSample::playOnce() { // long length=myDataSize*(0.5/myChannels); - short* buffer = (short *)myData; + // short* buffer = (short *)myData; + short* buffer = temp; position=(position+1); double remainder = position - (long) position; if ((long) position=0) { if ((long) position>=length-1) position=1; @@ -525,7 +567,9 @@ double maxiSample::play(double frequency, double start, double end, double &pos) if (end>=length) end=length-1; long a,b; - short* buffer = (short *)myData; +// short* buffer = (short *)myData; + short* buffer = temp; + if (frequency >0.) { if (pos0.) { if (position=0) { if ((long) position>=length-1) position=1; -- cgit v1.3