# Import Audio: Plug-in

**URL:** https://forum.juce.com/t/import-audio-plug-in/28025
**Category:** Audio Plugins
**Created:** [June 7, 2018, 11:24am UTC](https://forum.juce.com/t/import-audio-plug-in/28025 "2018-06-07T11:24:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Klod-Lunch](https://avatars.discourse-cdn.com/v4/letter/k/e8c25b/32.png) [@Klod-Lunch](https://forum.juce.com/u/Klod-Lunch)
#### Post date: [June 7, 2018, 11:24am UTC](https://forum.juce.com/t/import-audio-plug-in/28025/1 "2018-06-07T11:24:58Z")

</div>

Hi there,

I am fairly new to Juce. I am trying to make a plug-in in which I import an audio file.

I followed the audioplayer tutorial but this is done using the Audio App mode not Plug-in.

I’ve accessed the file like so:

`std::unique_ptr<AudioFormatReader> reader (formatManager.createReaderFor (filepath));`

And read it to a AudioSampleBuffer object:

```
fileBuffer.setSize(reader->numChannels, (int) reader->lengthInSamples);
reader->read(&fileBuffer, 0, (int) reader->lengthInSamples, 0, true, true);

```

I’m not sure what to do next to grab that audio file data in the processBlock method so I can manipulate it (I will be processing it together with audio incoming from my DAW).

Would I say something like:

`auto samplesToProcess = fileBuffer.getNumSamples() // my wav file`  
`auto* channelData = buffer.getWritePointer (channel) + sampleToProcess; // DAW audio + wav file`

(This didn’t work, but shows my thinking).

Thank you to anyone who points me in the right direction, I am learning how all the components in Juce come together structurally, so am appreciative of corrections of my current misconceptions 🙂

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)
#### Post date: [June 7, 2018, 11:42am UTC](https://forum.juce.com/t/import-audio-plug-in/28025/2 "2018-06-07T11:42:09Z")

</div>

What you do is to iterate over the samples. There are several options to achieve that:

1. manipulate the whole buffer at once, using -\> [AudioBuffer::addFrom()](https://docs.juce.com/develop/classAudioBuffer.html#abb2b03021cca3f0382d602d0b9755a08)
2. iterate over the samples and add them, e.g. `*channelData += waveData[i];` (with `auto* waveData = fileBuffer.getReadPointer (channel);`)

Make sure you keep the index to the next sample in your fileBuffer as a member, since each buffer is so small, each time you will only process a fraction of your wav file.

HTH

---

<div class="post-metadata">

### Author: ![Klod-Lunch](https://avatars.discourse-cdn.com/v4/letter/k/e8c25b/32.png) [@Klod-Lunch](https://forum.juce.com/u/Klod-Lunch)
#### Post date: [June 8, 2018, 12:09pm UTC](https://forum.juce.com/t/import-audio-plug-in/28025/3 "2018-06-08T12:09:14Z")

</div>

Hi Daniel, thank you very much - it works!

I chose the second option, with a separate variable to store the index of the wav sample as you suggested. Very happy, I can move on to the next step now.
