Difference between revisions of "CSC111 JES Page on Sound Processing"

From dftwiki3
Jump to: navigation, search
(Sound Files)
(Part 3: Altering a sound file)
Line 78: Line 78:
 
</source>
 
</source>
 
<br />
 
<br />
 +
=Part 4: Reversing a Sound File=
 +
 +
<center>[[Image:CSC111_lab3_sound1_sound2.png | 300px]]</center>
 +
 +
* The goal is to create 2 sound objects, '''sound1''' and '''sound2''' from the same file, and take the value of the sample at Index 1  in sound1 and to store it at Index N-1 in sound2.  Identically for the sample at Index 2 which will go to Index N-2 in sound2.
 +
 +
* Complete the table below and write down the relationship existing between i and j:
 +
 +
<br />
 +
<br />
 +
<br />
 +
 +
<center>
 +
{| border="1"
 +
| &nbsp;&nbsp;i&nbsp;&nbsp;
 +
| &nbsp;&nbsp;j&nbsp;&nbsp;
 +
| &nbsp;&nbsp;i+j&nbsp;&nbsp;
 +
|-
 +
| &nbsp;1
 +
| &nbsp;
 +
| &nbsp;
 +
|-
 +
| &nbsp;2
 +
| &nbsp;
 +
| &nbsp;
 +
|-
 +
| &nbsp;3
 +
| &nbsp;
 +
| &nbsp;
 +
|-
 +
| ...
 +
| &nbsp;
 +
| &nbsp;
 +
|-
 +
| N-2
 +
| &nbsp;
 +
| &nbsp;
 +
|-
 +
| N-1
 +
| &nbsp;
 +
| &nbsp;
 +
|}
 +
</center>
 +
<br />
 +
<br />
 +
<br />
 +
 +
* From the table above extract the equation that yields ''j'' as a function of ''i''
 +
* Write your for-loop to reverse sound1 into sound2
 +
 +
      N = ...
 +
      for i in range( 1, N ):
 +
            j = ...
 +
            sample = getSampleValueAt( sound1, i )
 +
            setSampleValueAt( sound2, j, sample )
 +
 +
* Test your program by making it play sound1 first, then sound2.

Revision as of 20:21, 23 February 2014

--D. Thiebaut (talk) 20:12, 23 February 2014 (EST)


Reference

Installation


Sound Files


  • Get some sample wav files:


If you want to install JES on your personal Windows computer


If you want to install JES on your Windows laptop or computer, you can get Jes from the Google code web site. Grab the 3.2.1 version for Windows and install it on your Windows machine.

If you want to install JES on your personal Mac


Jes for the Mac is available on Google code. Get Jes 3.2.1 for the Mac, open the zip file, and move the JES 3.2.1.app to your Applications folder.

Example 1: Playing Sound Files

  • In the JES program area, type in the following main() function:


file = pickAFile()
sound = makeSound( file )
blockingPlay( sound )


  • Save the file as sound1.py
  • Click on Load Program
  • In the interactive area, type
  • When prompted for a sound file, select thisisatest.wav in the Sound Files folder.
  • Make sure the speakers are on, but not too loud and listen to the sentence being played.
  • Try one or two other sound files.



Part 3: Altering a sound file


  • You will reduce the intensity of the sound by dividing all the samples by half
  • Copy/Paste the program below in JES
  • Read it to make sure you understand it.


  # select  a sound file
  file = pickAFile()
  sound = makeSound( file )

  # play it
  blockingPlay( sound )

  # lower its intensity by half
  for i in range( 1, getLength( sound ) ):
     value = getSampleValueAt( sound, i )    # get the value of the i-th sample
     setSampleValueAt( sound, i, value / 2 )  # set the sample to half its original value

  # play new waveform back
  blockingPlay( sound )


Part 4: Reversing a Sound File

CSC111 lab3 sound1 sound2.png
  • The goal is to create 2 sound objects, sound1 and sound2 from the same file, and take the value of the sample at Index 1 in sound1 and to store it at Index N-1 in sound2. Identically for the sample at Index 2 which will go to Index N-2 in sound2.
  • Complete the table below and write down the relationship existing between i and j:




  i     j     i+j  
 1    
 2    
 3    
...    
N-2    
N-1    




  • From the table above extract the equation that yields j as a function of i
  • Write your for-loop to reverse sound1 into sound2
      N = ...
      for i in range( 1, N ):
           j = ...
           sample = getSampleValueAt( sound1, i )
           setSampleValueAt( sound2, j, sample )
  • Test your program by making it play sound1 first, then sound2.