# Is there a way to play a SoundFile muted and keep its amplitude data?

**URL:** https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830
**Category:** Libraries
**Created:** [April 1, 2019, 9:38am UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830 "2019-04-01T09:38:51Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [April 1, 2019, 9:38am UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/1 "2019-04-01T09:38:51Z")

</div>

Trying to gather data from a sound file without listening to it, but I’m having trouble getting there. I thought I might be able to do it by playing the file in draw(), gathering the FFT spectrum data, then pausing at the end.

I tried the reverse order first to make sure the sound is working properly, but the results were strange. I thought that draw() would only render the final state of the file, so if I put play last, it would just play it, but it seems every draw() frame it pauses and plays, chopping up and slowing down the sample in half. Below is an example of the code I’m using with sin440.wav as a stand-in for whatever sound file you want to use.

```auto
import processing.sound.*;

SoundFile file;

void setup() {
  size(200, 200);
  background(255);

  
  String audio ="sin440.wav";
  file = new SoundFile(this, audio);

}

void draw() {
if (file.isPlaying()){
  file.pause();

}
if (!file.isPlaying()){
  file.play();

}

}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 1, 2019, 2:11pm UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/2 "2019-04-01T14:11:11Z")

</div>

i think

> / Files / Examples / Minim / Analysis / FFT / offlineAnalysis

does what you try to do on a sound file.

 ![SNAG-0049](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/77d43a367ded391f734cc2628be6b4c5408b27ed.jpeg)  
but it is a very complex example!

---

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [April 1, 2019, 2:46pm UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/3 "2019-04-01T14:46:49Z")

</div>

Thanks for the research. I haven’t used the minim library yet. I’ll look into it.

Do you know by any chance why play/pause acts this way in the above example?

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [April 2, 2019, 5:17pm UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/4 "2019-04-02T17:17:06Z")

</div>

> [@Aeggy](#):
>
> Trying to gather data from a sound file without listening to it

For that I would recommend minim – but if you want to do it with the Sound library, you should start by working with the FFT analysis example:

> **[FFT / Libraries](https://processing.org/reference/libraries/sound/FFT.html)**
>
> This is a Fast Fourier Transform (FFT) analyzer. It calculates the normalized power spectrum of an audio stream the moment it is queried with the analyze() method.

Starting point suggestions: consider how Sound enables you to map input-output devices, or how fft.input allows you to patch a source.

> **[Sound / Libraries](https://processing.org/reference/libraries/sound/Sound.html)**
>
> This class can be used for configuring the Processing Sound library. The Sound class allows for configuring global properties of the sound library's audio synthesis and playback, such as the output de…

---

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [April 3, 2019, 12:11am UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/5 "2019-04-03T00:11:19Z")

</div>

> [@jeremydouglass](#):
>
> > [@Aeggy](#):
> >
> > Trying to gather data from a sound file without listening to it
> 
> Starting point suggestions: consider how Sound enables you to map input-output devices, or how fft.input allows you to patch a source.

Could you elaborate on how I might solve this problem with the use of mapping input/output devices?

With regards to FFT.input, it seems like it only analyzes when .play() is active. Is that a correct observation? That’s what I’ve tried to work with in the sound library. Play the sound, get the FFT spectrum, Pause, next draw frame, repeat. However, all combinations and methods I tried with that library so far have either resulted in Play being called again and again, overloading the soundcard, or a stuttery/clicky pause-play-pause-play, etc. that halves the speed of the source. Can’t get one draw frame to Play and Pause smoothly in one go.

My guess right now is that .play() executes at the end of a draw frame no matter where it’s placed in the code. Also that each draw frame creates its own instance of .play/pause/stop() and the next instance can’t interact with the previous. Do you know if I got any of that right? haha.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 3, 2019, 1:13am UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/6 "2019-04-03T01:13:06Z")

</div>

may i draw that in a cartoon?

you sit in your armchair, and shout!

> darling, switch ON the TV

> darling, switch OFF the TV

and you do that 60 times per second!  
what you will get?

> divorce

* * *

actually what you try to do should not involve SOUND stream at all,  
what you need would be to read the data from file  
( and that i do not know how to do from today sound files )  
in 512 array batches and run your own FFT on that array.  
and on keyPressed read the next 512 lines.

---

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [April 3, 2019, 4:20am UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/7 "2019-04-03T04:20:09Z")

</div>

Haha, nice. Yeah, if I knew how to just read it from the file I would, unfortunately I’m an amateur who struggles with things I assume pros could do in a couple seconds.

For now my solution was just to lower the amp to an inaudible amount and just use the map function when I need to use the data.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [April 3, 2019, 8:16am UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/8 "2019-04-03T08:16:28Z")

</div>

i show you the way??

> [@kll](#):
>
> Minim / Analysis / FFT / offlineAnalysis

---

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [April 3, 2019, 8:02pm UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/9 "2019-04-03T20:02:09Z")

</div>

Yes, but like you said, it’s quite complicated. For now, lowering the amp is a simpler solution for me.

Thanks kll.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [April 4, 2019, 12:00pm UTC](https://discourse.processing.org/t/is-there-a-way-to-play-a-soundfile-muted-and-keep-its-amplitude-data/9830/10 "2019-04-04T12:00:19Z")

</div>

> [@Aeggy](#):
>
> Could you elaborate on how I might solve this problem with the use of mapping input/output devices?

I honestly don’t know – it might be possible, which is why I suggested it as a starting point, but I can only recall seeing minim actually used for this, which is why I recommended that instead.
