# As a newbie I just want to load a sample and play it

**URL:** <https://forum.juce.com/t/as-a-newbie-i-just-want-to-load-a-sample-and-play-it/24108>\
**Category:** Audio Plugins\
**Created:** [September 8, 2017, 7:25pm UTC](https://forum.juce.com/t/as-a-newbie-i-just-want-to-load-a-sample-and-play-it/24108 "2017-09-08T19:25:46Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![zonrobin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/zonrobin/32/1961_2.png) [@zonrobin](https://forum.juce.com/u/zonrobin)\
**Post date:** [September 9, 2017, 6:26pm UTC](https://forum.juce.com/t/as-a-newbie-i-just-want-to-load-a-sample-and-play-it/24108/7 "2017-09-09T18:26:48Z")

</div>

Sorry, I didn’t mention that `readFromAudioReader` is not available anymore. The `AudioFormatReader` `read()` is what you need. Just search the forum, there’s plenty of answers for this - here’s another thread:

> [@Mixing WAV and AudioSampleBuffer](https://forum.juce.com/t/mixing-wav-and-audiosamplebuffer/21067):
>
> Hi, Right now I am trying to combine the AudioSampleBuffer given from the proccessBlock method, with an AudioSampleBuffer that I created from a WAV file. I am mixing them using the addFrom method. When I am encountering is a ‘buzzing’ sound ontop of the other track when I apply my filter, as opposed to the desired mix of the two buffers. When I create a reader for the WAV, usingFloatingPointData is false. The sample rate of the WAV matches the sample rate of the audio file I’ve been testing…

I rewrote the code (but didn’t tested). Call `read()` and increment `sourceStartSample` in each iteration of `processBlock` by `numReadSamples`. Don’t forget to reset it when it goes to end, fill the rest of the `outputBuffer` with zeros when there’s not enough samples (or `clear()` at the beginning of iteration), etc.

```
AudioSampleBuffer outputBuffer;
String path = "someFile.wav";
int64 sourceStartSample = 0;
int numReadSamples = 512;

File soundFile = File(path);
AudioFormatManager manager;
manager.registerBasicFormats();
AudioFormatReader* reader = manager.createReaderFor(soundFile);
outputBuffer.setSize((int)reader->numChannels, (int)reader->lengthInSamples);
reader->read(&outputBuffer, 0, jmin((int)reader->lengthInSamples, numReadSamples), sourceStartSample, true, true);

```

Combine the `FileChooser` (from the tutorial) with this and you might get what you need.

Or you can implement it similary to how the [SoundPlayer](https://www.juce.com/doc/classSoundPlayer) does.

About over engineering - one shouldn’t forget that JUCE is cross-platform and it doesn’t use any external libraries AFAIK.

---

_[View the full topic](https://forum.juce.com/t/as-a-newbie-i-just-want-to-load-a-sample-and-play-it/24108)._
