• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Converting audio file to create an image and into a format usable by Picture class?

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I'm back once again with more questions

Okay so...
I have to write a program that uses StdAudio and Picture to create an interesting two-dimensional color visualization of a sound file while it is playing.

I'm not sure how to even start this one...

But here's what I know how to do that might possibly help me with making this program:

- Grab the width and height, and the color values(as integers) of each pixels from an image.
- Read the samples from an audio file(.wav) and grab them as an array of doubles.

My instructor gave me some hints and wrote/drew this:


So basically I have to "create" an image using the values of double[]'s that I grab from the sound file? So I actually have to create an image, not pick an image to use? The sound file is supposed to "create" the image for me?
Then use those values from the sound file and plug them in in the equations above? As well as whatever rows, and the width of whatever I want to set it to?
Then whatever results I get from "1D Array Loc % 4 = col" and "1D Array Loc / 4 = row" will be the values I use for ?

Thanks! Any help/feedback would be greatly appreciated!
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bump.
 
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your "requirements" are very vague. Your diagram shows a 4x4 grid, is that a grid of pixels or images? How would you use sound to compute the Color? I know what a picture is but I don't know what a "Picture" (class?) is. I assume the picture is supposed to change as the sound file is played. How do you sync the process of converting a section of the double array to a picture to move to the next position in the array in sync with the playback? Has your instructor shown you a working demo of an example of what they are looking for?

I'm afraid that without filling some more of the details you aren't likely to get many responses.
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Your "requirements" are very vague. Your diagram shows a 4x4 grid, is that a grid of pixels or images? How would you use sound to compute the Color? I know what a picture is but I don't know what a "Picture" (class?) is. I assume the picture is supposed to change as the sound file is played. How do you sync the process of converting a section of the double array to a picture to move to the next position in the array in sync with the playback? Has your instructor shown you a working demo of an example of what they are looking for?

I'm afraid that without filling some more of the details you aren't likely to get many responses.



The 4x4 is supposed to be a grid of pixels.  I have provided the like to the Picture class, we are supposed to use some of the methods from it.  I believe the double array is supposed to turn into colors.  My instructor didn't not show a demo, he only showed grabbing the array of doubles from a sound file.  I remember he said something about assigning each values to something?  And how were supposed to assign them according to the different kind of values... like negative, if values ends with certain numbers, etc.  I'm actually really confused.  My instructor extended the due date because everyone seems to be struggling as well.
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is similar to what we're supposed to do, demo.

Edit:
 
Carey Brown
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you pointed at appears to create a simple graph of the audio left & right double values. Is that the kind of "Picture" you have in mind? Also, I'm not familiar with the libraries the instructor is using.
 
Carey Brown
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jon Fil wrote:The 4x4 is supposed to be a grid of pixels.


4x4 pixels would be barley visible on a screen. (?)
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

Jon Fil wrote:The 4x4 is supposed to be a grid of pixels.


4x4 pixels would be barley visible on a screen. (?)



Oh that 4x4 was just an example.  My instructor drew that to show us and help us "understand" the stuff better.
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:The code you pointed at appears to create a simple graph of the audio left & right double values. Is that the kind of "Picture" you have in mind? Also, I'm not familiar with the libraries the instructor is using.



So from the StdAudio, there's a method which Reads audio samples from a file (in .wav or .au format) and returns them as a double array with values between -1.0 and +1.0.
And so I was thinking that maybe those are the values I use for the equations to get values for "1D Array Loc", "col", and "rows".  Then maybe somewhat convert col and row to int to use for and with color of my choice? Idk to be honest
 
Carey Brown
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jon Fil wrote:So from the StdAudio, there's a method which Reads audio samples from a file (in .wav or .au format) and returns them as a double array with values between -1.0 and +1.0.
And so I was thinking that maybe those are the values I use for the equations to get values for "1D Array Loc", "col", and "rows".  Then maybe somewhat convert col and row to int to use for and with color of my choice? Idk to be honest


Yes, that would give you a simple graph though you'd need more than 4x4 pixels and row would need to be scaled and offset.
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my code now.


Now, how would I make the picture(s) go in sync with the sound?
 
Carey Brown
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jon Fil wrote:Now, how would I make the picture(s) go in sync with the sound?


That was my question to you earlier. Based on the code in Git it looks like they queue up a few wave files and generate a picture at the start of each wave file but make no attempt at synchronizing while the file is playing.
 
Carey Brown
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thing in your code that is questionable is how you calculate the Color. The double passed in is presumably in the range of -1.0 to +1.0. So your formula (d + 1) / 2 will give you a range of 0.0 to 1.0 and that multiplied by 255 will give you 0 to 255. This is good because that is the valid range for rgb values. However you use multipliers of 355 and 380 for the other two rgb values which will probably overflow the 255 limit.

Where did you get this formula from?
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Another thing in your code that is questionable is how you calculate the Color. The double passed in is presumably in the range of -1.0 to +1.0. So your formula (d + 1) / 2 will give you a range of 0.0 to 1.0 and that multiplied by 255 will give you 0 to 255. This is good because that is the valid range for rgb values. However you use multipliers of 355 and 380 for the other two rgb values which will probably overflow the 255 limit.

Where did you get this formula from?



I originally only had

but I was messing with it trying to see different colors instead of just having all same value for color (r, g, b).  I also tried int r., g, b with ...* 255 for all three.
 
Carey Brown
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about this for Color?
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now, I'm stuck and can't make the color go in sync with the sound.


Should I be using while loop instead or?
 
Jon Fil
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Update:

I went and showed my instructor my code for some help and commented out is his feedback:



- How would I even set the size of the picture based on the audio?  If width of 500/44100hz is only 0.01 of a second, then how would it be if the sample length of my audio is 254646 when I do audio.length? Plus the sound file I'm using is only about 6 seconds long.
- If I don't need JFrame, then how would I even get the picture to animate?
- If I don't need the audio to play unless I wanna hear it, does this mean I even have to sync the colors and have picture/color animation at all???
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic