예제 #1
0
파일: playback.hpp 프로젝트: c41x/Kiwano
//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
	if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
		const auto &fname = c + 1;

		// stop current playback
		ts.stop();
		ts.setSource(nullptr);
		frs = nullptr;
		AudioFormatReader *r;

		// ectract CUE information (if any)
		std::regex cue("^(.*):(\\d+):(\\d+)$");
		std::smatch result;
		std::regex_search(fname->s, result, cue);
		if (result.size() == 4) {
			// is cue
			int32 start = base::fromStr<int32>(result[2].str());
			int32 end = base::fromStr<int32>(result[3].str());
			int32 duration = end - start;

			AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));

			// start, end are in frames (1 frame = 1/75 second) - convert to sample
			float samplesInOneSecond = tr->sampleRate; // AudioSubsectionReader will handle channels count
			float startSecond = (float)start / 75.0f;
			float durationSecond = (float)duration / 75.0f;
			float startSample = startSecond * samplesInOneSecond;
			float durationSamples = durationSecond * samplesInOneSecond;

			// some CUE may have 0 length (play to end)
			if (end <= start)
				durationSamples = tr->lengthInSamples;

			r = new AudioSubsectionReader(tr, (int)startSample, (int)durationSamples, true);
		}
		else {
			// regular file
			r = fm.createReaderFor(File(fname->s));
		}

		if (r) {
			frs = new AudioFormatReaderSource(r, true);
			ts.setSource(frs, 32768, &thread, r->sampleRate);
			return gl.t();
		}
		gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
		return gl.nil();
	}
	gl.signalError("playback-set-file: invalid arguments, expected (string)");
	return gl.nil();
}
예제 #2
0
void IRAgent::setFile(const File& file, size_t fileChannel)
{
  AudioFormatManager formatManager;
  formatManager.registerBasicFormats();
  ScopedPointer<AudioFormatReader> audioFormatReader(formatManager.createReaderFor(file));
  {
    ScopedLock lock(_mutex);
    if (audioFormatReader)
    {
      if (_file == file && _fileChannel == fileChannel)
      {
        return;
      }
      _file = file;
      _fileSampleCount = static_cast<size_t>(audioFormatReader->lengthInSamples);
      _fileChannelCount = static_cast<size_t>(audioFormatReader->numChannels);
      _fileSampleRate = audioFormatReader->sampleRate;
      _fileChannel = fileChannel;
    }
    else
    {
      _file = File::nonexistent;
      _fileSampleCount = 0;
      _fileChannelCount = 0;
      _fileSampleRate = 0.0;
      _fileChannel = 0;
    }
  }
  propagateChange();
  updateConvolver();
}
예제 #3
0
  void setTickSample (void const* audioData, int dataBytes)
  {
    ScopedPointer <MemoryInputStream> mis (new MemoryInputStream (audioData, dataBytes, false));

    m_synth.clearVoices ();
    m_synth.clearSounds ();

    AudioFormatManager afm;
    afm.registerBasicFormats ();
    
    {
      ScopedPointer <AudioFormatReader> afr (afm.createReaderFor (mis));

      if (afr != nullptr)
      {
        mis.release ();

        BigInteger midiNotes;
        midiNotes.setRange (0, 127, true);

        SynthesiserSound::Ptr sound = new SamplerSound (
          "Tick",
          *afr,
          midiNotes,
          60,
          0,
          0,
          60./40.);

        m_synth.addSound (sound);
        m_synth.addVoice (new SamplerVoice);
      }
    }

  }
예제 #4
0
void TrackComponent::filesDropped(const StringArray & files, int x, int)
{
    for (auto current = files.begin(), end = files.end(); current != end; ++current)
    {
        const String fileString = *current;
        String format;
        if(fileString.contains(".wav") || fileString.contains(".WAV"))
            format = "WAV";
        else if(fileString.contains(".aif") || fileString.contains(".aiff") || fileString.contains(".AIF") || fileString.contains(".AIFF"))
            format = "AIFF";
        else if(fileString.contains(".flac") || fileString.contains(".FLAC"))
            format = "FLAC";
        File file(fileString);
        AudioFormatManager formatManager;
        formatManager.registerBasicFormats();
        
        AudioFormatReader* reader = formatManager.createReaderFor(file);
        Region* region = new SampleRegion(reader, 1, &file);
        if(x > _mixerOffset)
        {
            int64 samplesRange = secondsToSamples((double)_numberOfClips, _sampleRate);
            int64 positionSamples = pixelsToSamples(x - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
            
            _track->add(positionSamples, region);
            createRegionGUI(x, region, formatManager, file);
        }
        else if(x < _mixerOffset)
        {
            _track->add(0, region);
            createRegionGUI(_mixerOffset, region, formatManager, file);
        }
    }
}
예제 #5
0
Oscillator::Oscillator (double sampleRate)
:			
	sampRate(sampleRate),
	squareBuffer(1, 22071),
	sawBuffer(1, 21984),
	sawDownBuffer(1, 21984)
{
	currentPhase = 0.0; 
	currentSample = 0.0;
	stepSize = 0;
	squareBuffer.clear();
	sawBuffer.clear();
	sawDownBuffer.clear();
	
	sharedMemory.enter();
	AudioFormatManager formatManager;
	formatManager.registerBasicFormats();
	
    ScopedPointer <AudioFormatReader> squareReader 
    (formatManager.createReaderFor(new MemoryInputStream (MainBinaryData::squarewave20500_wav,
                                                          MainBinaryData::squarewave20500_wavSize,
                                                          false)));
    
	squareReader->read(&squareBuffer, 0, squareReader->lengthInSamples, 0, true, false);
	
    squareNumSamples = squareReader->lengthInSamples;
	
	ScopedPointer <AudioFormatReader> sawReader 
    (formatManager.createReaderFor(new MemoryInputStream (MainBinaryData::sawwave20500_wav,
                                                          MainBinaryData::sawwave20500_wavSize,
                                                          false)));
    
	sawReader->read(&sawBuffer, 0, sawReader->lengthInSamples, 0, true, false);
	
	ScopedPointer <AudioFormatReader> sawDownReader
    (formatManager.createReaderFor(new MemoryInputStream (MainBinaryData::sawdownwave20500_wav,
                                                          MainBinaryData::sawdownwave20500_wavSize,
                                                          false)));
    
	sawDownReader->read(&sawDownBuffer, 0, sawDownReader->lengthInSamples, 0, true, false);
	
	sawNumSamples = sawReader->lengthInSamples; 
	
	sharedMemory.exit();
}
예제 #6
0
AudioFormatReader* AudioFilePlayer::audioFormatReaderFromFile(const File& audioFile)
{	
	AudioFormatManager formatManager;
	formatManager.registerBasicFormats();
	
	currentFile = audioFile;
	
	return formatManager.createReaderFor (audioFile);
}
KeyAnalysisThread::KeyAnalysisThread(SingleAudioFileForAnalysis* _fileToAnalyze, AudioFormatManager& _audioFormatManager)
	: Thread("Key Analysis Thread" + _fileToAnalyze->getFileName()),
	fileToAnalyze(_fileToAnalyze)
	//audioFormatManager(_audioFormatManager)
{
	audioFormatReader = _audioFormatManager.createReaderFor(_fileToAnalyze->getFileToBeAnalyzed());
	DBG("Creating thread: " << getThreadName());
	interval = Random::getSystemRandom().nextInt(50) + 8;
	startThread();
}
예제 #8
0
void AudioFilePlayer::setPolyphony (int value)
{
    int arraySize = fileSource.size();
    
    if (value > arraySize)
    {
        AudioFormatManager formatManager;
        formatManager.registerBasicFormats();
        ScopedPointer <AudioFormatReader> reader (formatManager.createReaderFor (currentFile));
        
        for (int i = 0; i < (value - arraySize); i++)
        {
            //add element
            fileSource.add (new AudioTransportSource());
            //add new element as an input source to audioMixer
            audioMixer.addInputSource(fileSource.getLast(), false);
            
            //apply audio file to new element
            if (currentFile != File::nonexistent)
            {
                //here, do I need to do the... 
                
                //if (reader != 0)
                //{
                ///    currentAudioFileSource = new AudioFormatReaderSource (reader, true);
                //}
                
                //... like in setAudioFile() above?
                //this will involve having to delete currentAudioFileSource first.
                
                addtoFileSourceArray (fileSource.size()-1, reader);
            }
        }
        
        //set AFTER elements have been created so any calls to
        //isCurrentlyPlaying() don't cause a crash due to 
        //elements not existing yet.
        polyphony = value;
    }
    else if (value < arraySize)
    {
        //set BEFORE elements have been deleted so any calls to
        //isCurrentlyPlaying() don't cause a crash due to 
        //elements not existing anymore.
        polyphony = value;
        
        for (int i = 0; i < (arraySize - value); i++)
        {
            //remove elements
            audioMixer.removeInputSource(fileSource.getLast());
            fileSource.removeLast();
        }
    }
    
}
예제 #9
0
//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
    if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
        const auto &fname = c + 1;

        // stop current playback
        ts.stop();
        ts.setSource(nullptr);
        frs = nullptr;

        AudioFormatReader *r;

        // ectract CUE information (if any)
        std::regex cue("^(.*):(\\d+):(\\d+)$");
        std::smatch result;
        std::regex_search(fname->s, result, cue);
        if (result.size() == 4) {
            // is cue
            int32 start = base::fromStr<int32>(result[2].str());
            int32 end = base::fromStr<int32>(result[3].str());
            AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));
            r = new AudioSubsectionReader(tr, start, end - start, true);
        }
        else {
            // regular file
            r = fm.createReaderFor(File(fname->s));
        }

        if (r) {
            frs = new AudioFormatReaderSource(r, true);
            ts.setSource(frs, 32768, &thread, r->sampleRate);
            return gl.t();
        }
        gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
        return gl.nil();
    }
    gl.signalError("playback-set-file: invalid arguments, expected (string)");
    return gl.nil();
}
예제 #10
0
bool FileWatcherThread::readDataFile(AudioSampleBuffer *buffer, File file) {
    AudioFormatManager formatManager;
    formatManager.registerBasicFormats();
    ScopedPointer<AudioFormatReader> reader = formatManager.createReaderFor(file);

    if (reader != 0) {
        int sampleCount = (int) reader->lengthInSamples;
        buffer->setSize(kNumSampleChannels, sampleCount, false, true, false);
        reader->read(buffer, 0, sampleCount, 0, true, true);
        if (reader->numChannels != kNumSampleChannels) {
            printf("File is mono, copying data to second channel\n");
            buffer->copyFrom(1, 0, *buffer, 0, 0, sampleCount);
        }
        return true;
    }

    return false;
}
예제 #11
0
//called from either the constructor, or setSamplerAudioFilePath() in PadSettings
void AudioFilePlayer::setAudioFile (File audioFile_)
{
    if (audioFile_ != File::nonexistent)
    {
        //passes in pads audio file
        File audioFile (audioFile_);
        
        //if the audio file is different from the previous one, stop and load in the new file
        if (audioFile != currentFile)
        {
            // unload the previous file source and delete it..
            broadcaster.sendActionMessage("OFF");
            
            for (int i = 0; i < polyphony; i++)
            {
                fileSource[i]->stop();
                fileSource[i]->setPosition(0.0);
                fileSource[i]->setSource (0);
            }
            deleteAndZero (currentAudioFileSource);
            
            // create a new file source from the file..
            // get a format manager and set it up with the basic types (wav, ogg and aiff).
            AudioFormatManager formatManager;
            formatManager.registerBasicFormats();
            
            AudioFormatReader* reader = formatManager.createReaderFor (audioFile);
            
            if (reader != 0)
            {
                currentFile = audioFile;
                currentAudioFileSource = new AudioFormatReaderSource (reader, true);
                
                //add the audio file to the fileSource array
                for (int i = 0; i < polyphony; i++)
                {
                    addtoFileSourceArray(i, reader);
                }
  
            }
        }
    }
}
예제 #12
0
    void loadFileIntoTransport (const File& audioFile)
    {
        // unload the previous file source and delete it..
        transportSource.stop();
        transportSource.setSource (nullptr);
        currentAudioFileSource = nullptr;

        AudioFormatReader* reader = formatManager.createReaderFor (audioFile);

        if (reader != nullptr)
        {
            currentAudioFileSource = new AudioFormatReaderSource (reader, true);

            // ..and plug it into our transport source
            transportSource.setSource (currentAudioFileSource,
                                       32768,                   // tells it to buffer this many samples ahead
                                       &thread,                 // this is the background thread to use for reading-ahead
                                       reader->sampleRate);     // allows for sample rate correction
        }
    }
예제 #13
0
void DiskIn::initWithJuceFile(File const& file, 
							  bool loopFlag, 
							  const double startTime, 
							  const int numFrames,
							  const UGen::DoneAction doneAction) throw()
{
	AudioFormatManager formatManager;
	formatManager.registerBasicFormats();
	
	AudioFormatReader* reader = formatManager.createReaderFor (file);
	int numChannels = reader->numChannels;
	delete reader;
	
	initInternal(numChannels);
	generateFromProxyOwner(new DiskInUGenInternal(file, 
												  numChannels, 
												  loopFlag, 
												  startTime, 
												  numFrames, 
												  doneAction));	
}
void AudioDemoPlaybackPage::loadFileIntoTransport (const File& audioFile)
{
    // unload the previous file source and delete it..
    transportSource.stop();
    transportSource.setSource (0);
    deleteAndZero (currentAudioFileSource);

    // get a format manager and set it up with the basic types (wav and aiff).
    AudioFormatManager formatManager;
    formatManager.registerBasicFormats();

    AudioFormatReader* reader = formatManager.createReaderFor (audioFile);

    if (reader != 0)
    {
        currentAudioFileSource = new AudioFormatReaderSource (reader, true);

        // ..and plug it into our transport source
        transportSource.setSource (currentAudioFileSource,
                                   32768, // tells it to buffer this many samples ahead
                                   reader->sampleRate);
    }
}
예제 #15
0
void TrackComponent::mouseDown(const MouseEvent &e) {

	ModifierKeys modifiers = ModifierKeys::getCurrentModifiersRealtime();

    int posX;
	// check the mod keys ..
	if (modifiers.isPopupMenu() || modifiers.isCtrlDown())
	{
		ScopedPointer<PopupMenu> trackMenu_ = new PopupMenu();
		trackMenu_->clear();
		trackMenu_->addCommandItem(&_commands, MainWindow::showMixer);
		trackMenu_->addItem(1, "Add Region", true);
        MouseEvent ev = e.getEventRelativeTo(this);
        for(auto region : _regionComponents)
        {
            posX = ev.x;
            region->setBroughtToFrontOnMouseClick(true);
            if(region->getPositionX() < posX && posX < (region->getPositionX() + region->getRegionWidth()))
            {
                trackMenu_->addItem(2, "Remove Region", true);
            }
        }
        switch (trackMenu_->show())
        {
            case 1:
            {
                FileChooser chooser("Select an audio file to add...",
                                    File::nonexistent,
                                    "*.wav; *aif; *.flac");
                if (chooser.browseForFileToOpen()) {
                    File audioFile(chooser.getResult());
                    const String fileString = audioFile.getFullPathName();
                    String format;
                    if (fileString.contains(".wav"))
                        format = "WAV";
                    else if (fileString.contains(".aif") || fileString.contains(".aiff"))
                        format = "AIFF";
                    else if (fileString.contains(".flac"))
                        format = "FLAC";
                    AudioFormatManager formatManager;
                    formatManager.registerBasicFormats();
                    
                    AudioFormatReader* reader = formatManager.createReaderFor(audioFile);
                    Audio::Region* region = new Audio::SampleRegion(reader, 1, &audioFile);
                    Point<int> position = e.getPosition();
                    int x = position.getX();
                    
                    if (x > _mixerOffset)
                    {
                        int64 samplesRange = secondsToSamples(100, _sampleRate);
                        int64 positionSamples = pixelsToSamples(x - _mixerOffset, 100 * _pixelsPerClip, samplesRange);
                        
                        _track->add(positionSamples, region);
                        createRegionGUI(x, region, formatManager, audioFile);
                        getParentComponent()->resized();
                    }
                    else if (x < _mixerOffset)
                    {
                        _track->add(0, region);
                        createRegionGUI(_mixerOffset, region, formatManager, audioFile);
                        getParentComponent()->resized();
                    }
                }
            }
                break;
            case 2:
            {
                CriticalSection critical;
                critical.enter();
                for(size_t i = 0; i < _regionComponents.size(); ++i)
                {
                    
                    Rectangle<int> bounds_ = _regionComponents.at(i)->getBounds();
					posX = ev.x;
                    if((int)_regionComponents.at(i)->getPositionX() < posX && posX < ((int)_regionComponents.at(i)->getPositionX() + (int)_regionComponents.at(i)->getRegionWidth()))
                    {
                        _track->remove(_regionComponents.at(i)->getRegion(), _posX.at(i));
                        std::vector<RegionComponent*>::iterator regit = _regionComponents.begin() + i;
                        RegionComponent* component = _regionComponents.at(i);
                        removeChildComponent(_regionComponents.at(i));
                        _regionComponents.erase(regit);
                        delete component;
                        _regions.erase(_posX.at(i));
                        std::vector<int64>::iterator posit = _posX.begin() + i;;
                        _posX.erase(posit);
                        std::vector<int64>::iterator sampsit = _sizeSamps.begin() + i;;
                        _sizeSamps.erase(sampsit);
                    }
                }
                critical.exit();
            }
            default:
                break;
        }
    }
}
예제 #16
0
bool Mcfx_convolverAudioProcessor::loadIr(AudioSampleBuffer* IRBuffer, const File& audioFile, int channel, double &samplerate, float gain, int offset, int length)
{
    if (!audioFile.existsAsFile())
    {
        std::cout << "ERROR: file does not exist!!" << std::endl;
        return false;
    }
    
    AudioFormatManager formatManager;
    
    // this can read .wav and .aiff
    formatManager.registerBasicFormats();
    
    AudioFormatReader* reader = formatManager.createReaderFor(audioFile);
    
    if (!reader) {
        std::cout << "ERROR: could not read impulse response file!" << std::endl;
        return false;
    }
    
	//AudioFormatReader* reader = wavFormat.createMemoryMappedReader(audioFile);
    
    int64 ir_length = (int)reader->lengthInSamples-offset;
    
    if (ir_length <= 0) {
        std::cout << "wav file has zero samples" << std::endl;
        return false;
    }
    
    if (reader->numChannels <= channel) {
        std::cout << "wav file doesn't have enough channels: " << reader->numChannels << std::endl;
        return false;
    }
    
    
    AudioSampleBuffer ReadBuffer(reader->numChannels, ir_length); // create buffer
    
    
    reader->read(&ReadBuffer, 0, ir_length, offset, true, true);
    
    // set the samplerate -> maybe we have to resample later...
    samplerate = reader->sampleRate;
    
    //std::cout << "ReadRMS: " << ReadBuffer.getRMSLevel(channel, 0, ir_length) << std::endl;
    
    // check if we want a shorter impulse response
    
    if (ir_length > length && length != 0)
        ir_length = length;
    
    // copy the wanted channel into our IR Buffer
    
    IRBuffer->setSize(1, ir_length);
    IRBuffer->copyFrom(0, 0, ReadBuffer, channel, 0, ir_length);
    
        
    // scale ir with gain
    IRBuffer->applyGain(gain);
    
    // std::cout << "ReadRMS: " << IRBuffer->getRMSLevel(0, 0, ir_length) << std::endl;
    
    delete reader;
    
    
    return true;
}
bool AudioSourceFilePrelistener::play(const String& absolutePathToAudioFile,
          const int& startPosition_, 
          const int& endPosition_)
{
    DEB("AudioSourceFilePreview::play called.");
    
    // If a new audio file is specified,
    // delete the old bufferingAudioSource and
    // create a new bufferingAudioSource
    if (absolutePathToAudioFile != previouslyUsedPathToAudioFile)
    {
        // delete the old audioFormatReaderSource
        // (exept the first time, when there is no audioFormatReaderSource)
        if (bufferingAudioSource != NULL)
        {
            bufferingAudioSource->releaseResources();
            delete bufferingAudioSource;
        }
        
        // \/ \/ \/ Similar to AudioRegionMixer::addRegion \/ \/ \/
        
        // --- begin{audio file stuff} ---
        File audioFile(absolutePathToAudioFile);
        
        // get a format manager and set it up with the basic types (wav and aiff).
        AudioFormatManager audioFormatManager;
        audioFormatManager.registerBasicFormats();
        // Currently, this registers the WAV and AIFF formats.
        
        AudioFormatReader* audioFormatReader = audioFormatManager.createReaderFor (audioFile);
        // This audioFormatReader will be deleted when the audioFormatReaderSource will
        // be deleted
        // --- end{audio file stuff} ---
        
        // if the previous lines of code weren't successful
        if (audioFormatReader == NULL)
        {
            DEB("AudioSourceFilePrelistener: The audio file couldn't be read.")
            delete audioFormatReader;
            bufferingAudioSource = NULL;
            runPlayback = false;
            return false;
        }
        // Check if this input set is invalid
        if (startPosition_ >= endPosition_
                 || startPosition_ < 0
                 || endPosition_ > audioFormatReader->lengthInSamples)
        {
            DEB("AudioSourceFilePrelistener: Didn't play because the given" 
                "startPosition (" + String(startPosition_) + ") and endPosition ("
                + String(endPosition_) + ") don't make sense.")
            delete audioFormatReader;
            bufferingAudioSource = NULL;
            runPlayback = false;
            return false;
        }
        
        // /\ /\ /\ End of similar to AudioRegionMixer::addRegion /\ /\ /\

        const bool deleteAudioFormatReaderWhenDeleted = true;
        AudioFormatReaderSource* audioFormatReaderSource = new AudioFormatReaderSource (audioFormatReader, deleteAudioFormatReaderWhenDeleted);
        bool deleteSourceWhenDeleted = true;
        bufferingAudioSource = new BufferingAudioSource (audioFormatReaderSource, deleteSourceWhenDeleted, 32768);
        bufferingAudioSource->prepareToPlay(samplesPerBlockExpected, sampleRate);
    }
    else
    // if (absolutePathToAudioFile == previouslyUsedPathToAudioFile)
    {
        // Check if this input set is invalid
        if (startPosition_ >= endPosition
            || startPosition_ < 0
            || endPosition_ > bufferingAudioSource->getTotalLength())
        {
            DEB("AudioSourceFilePrelistener: Didn't play because the given" 
                "startPosition (" + String(startPosition_) + ") and endPosition ("
                + String(endPosition_) + ") don't make sense.")
            runPlayback = false;
            return false;
        }
    }
    
    nextPlayPosition = startPosition_;
    endPosition = endPosition_;
    bufferingAudioSource->setNextReadPosition (nextPlayPosition);
    
    runPlayback = true;
    return true;
}
void Dictionary::createDictionary(std::string outputDir)
{
    //open output file
    std::fstream outputFile;
    outputFile.open(outputDir+"W.txt", std::ios::out);
    if (!outputFile.is_open()) {
        std::cout << "Text file open error!";
        return;
    }
    
    //prepare to read file
    AudioFormatManager formatManager;
    formatManager.registerBasicFormats();
    
    kiss_fft_cfg fwd= kiss_fft_alloc(FFT_SIZE,0,NULL,NULL);
    
    // HARD CODING HERE. REQUIRES MODIFICATION
    float fs = 44100;
    int nChannels = 2;
    numSamplesToRead = round(fs*SECS_PER_BLOCK);
    numSamplesPerBlock = numSamplesToRead/DOWNSAMPLE_RATE;
    
    AudioSampleBuffer buffer(nChannels, numSamplesToRead);
    float* audioBuffer = new float[numSamplesToRead];
    
    for (int track = 21; track<=108; track++) {
        
        // ANY BETTER WAYS TO DEAL WITH FILENAMES??
        std::string strFileDir = sampleFileFolder + "MAPS_ISOL_NO_M_S0_M"+std::to_string(track)+"_AkPnBcht.wav";
        File audioFileS0(strFileDir);
        
        AudioFormatReader* reader;
        
        if (audioFileS0.exists()) {
            reader = formatManager.createReaderFor(audioFileS0);
        }
        else {
            strFileDir = sampleFileFolder + "MAPS_ISOL_NO_M_S1_M"+std::to_string(track)+"_AkPnBcht.wav";
            File audioFileS1(strFileDir);
            reader = formatManager.createReaderFor(audioFileS1);
        }
        
        reader->read(&buffer, 0, numSamplesToRead, fs, true, true);
        
        float* leftBuffer = buffer.getSampleData(0);
        float* rightBuffer = buffer.getSampleData(1);
        
        for (int i=0; i<numSamplesToRead; i++) {
            audioBuffer[i] = (leftBuffer[i]+rightBuffer[i])/2;
        }
        
        antiAlias(audioBuffer, numSamplesToRead);
        
        
        for (int i=0; i<numSamplesPerBlock; i++) {
            audio[i].real( audioBuffer[i*DOWNSAMPLE_RATE]*hammWin(i, numSamplesPerBlock) );
            audio[i].imag(0);
        }
        for (int i = numSamplesPerBlock; i<FFT_SIZE; i++) {
            audio[i].real(0);
            audio[i].imag(0);
        }
        
        kiss_fft(fwd, (kiss_fft_cpx*) audio, (kiss_fft_cpx*)spectrum);
        for (int i = 0; i<FFT_SIZE/2; i++) {
            W[i][track-21] = abs(spectrum[i]);       //HARD CODING HERE!
        }
        
        delete reader;
        
    }
    delete [] audioBuffer;
    
    for(int i = 0; i< FFT_SIZE/2; i++){
        for (int j = 0; j<N_NOTES; j++) {
//            fwrite(&W[i][j], sizeof(float), 1, file);
            outputFile << W[i][j] << "\t";
        }
        outputFile<<std::endl;
    }
    
    outputFile.close();
    
}