Difference between revisions of "CSC231 Lab 6 2010"

From dftwiki3
Jump to: navigation, search
(Created page with '--~~~~ ---- __TOC__ <br /> <tanbox> This lab covers sound files in the WAV format, and performing various operations on a sound file using array operations. </tanbox> =The Forma…')
 
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] 13:51, 25 October 2010 (UTC)
 
--[[User:Thiebaut|D. Thiebaut]] 13:51, 25 October 2010 (UTC)
 
----
 
----
 +
[[Image:SoundWave.jpg | right | 300px]]
 +
 
__TOC__
 
__TOC__
 +
 +
 
<br />
 
<br />
 
<tanbox>
 
<tanbox>
Line 20: Line 24:
 
:or simply get them with '''getcopy'''
 
:or simply get them with '''getcopy'''
  
   getcopy readWaveFileSkel.asm
+
   getcopy readWavFileSkel.asm
 
   getcopy wav.inc
 
   getcopy wav.inc
  
 
==Get sound files==
 
==Get sound files==
* Get the sample wav files [[media:hello.wav | hello.wav]] and [[media:goodbye.wav|goodbye.wav]] as well:
+
* Get some sample wav files:
  
   getcopy hello.wav
+
   getcopy [[media:hello.wav |hello.wav]]
   getcopy goodbye.wav
+
   getcopy [[media:goodbye.wav|goodbye.wav]]
 +
  getcopy [[media:dratcomp.wav|dratcomp.wav]]
 +
  getcopy [[media:force.wav|force.wav]]
 +
  getcopy [[media:takeover.wav|takeover.wav]]
  
:''(there's more at http://buggerluggs.tripod.com/ie/wav-dir184.htm )''
+
* ''Note'': There's more at http://buggerluggs.tripod.com/ie/wav-dir184.htm and http://www.duke.edu/~rfb/palace/wavs/dratcomp.wav.  If you want to download more to your account, simply find the URL of a wav file, for example http://www.duke.edu/~rfb/palace/wavs/energize.wav, then type the following command at the prompt:
 +
 
 +
  wget http://www.duke.edu/~rfb/palace/wavs/energize.wav
  
 
==Play the sound==
 
==Play the sound==
Line 39: Line 48:
 
* '''Important''': make a note of the size of the samples, in this case 8 bits, unsigned.
 
* '''Important''': make a note of the size of the samples, in this case 8 bits, unsigned.
  
== Assemble ==
+
== Assemble, Link and Run ==
  
 
* Do not modify readWavFileSkel.asm yet.  On its own it will create a new copy of the goodbye.wav under the name goodbye2.wav.   
 
* Do not modify readWavFileSkel.asm yet.  On its own it will create a new copy of the goodbye.wav under the name goodbye2.wav.   
Line 47: Line 56:
  
 
  nasm  -f elf readWavFileSkel.asm
 
  nasm  -f elf readWavFileSkel.asm
  ld -o readWavFile readWavFile.o
+
  ld -melf_i386 -o readWavFileSkel readWavFileSkel.o
 
  rm goodbye2.wav
 
  rm goodbye2.wav
 
  ./readWavFileSkel
 
  ./readWavFileSkel
Line 63: Line 72:
 
=Part 2=
 
=Part 2=
  
==Test #1==
+
==Test #1: Increase intensity, the simple way==
 
* Make a copy of readWavFileSkel.asm and call it '''readWavFile1.asm'''
 
* Make a copy of readWavFileSkel.asm and call it '''readWavFile1.asm'''
  
* Modify it and modify it so that you multiply the intensity of the sound by 2.
+
* Modify   it so that you multiply the intensity of the sound by 2.
 +
 
 +
* Listen to the result.  Can you understand the message?
 +
 
 +
 
 +
==Test #2: Increase intensity, the more sophisticated way==
 +
 
 +
* You will have figured out that the previous method gives poor results.  Instead try to figure out how we can mulitply an 8-bit sample by 2 in such a way that if the result is less than 255, we keep it as is, but if it is larger than 255, we force the sample to 255.  In other words, figure out a way to implement this algorithm with the instructions you know:
 +
 
 +
      sample = buffer[ i ];
 +
      sample = sample * 2;
 +
      if sample > 255:
 +
        sample = 255
 +
 
 +
* implement your solution in you readWavFile1.asm file, assemble, link, and listen to the result...  Any better?
 +
 
 +
==Test #3-a: Decrease Intensity==
 +
* Same thing, but this time you will divide the intensity by 2.  A good way to divide by two is to shift the binary pattern to the right.  For example, to shift right the contents of eax by one bit, do this:
 +
 
 +
          shr      eax, 1
 +
 
 +
==Test #3-b: Decrease Intensity of a 16-bit Wav File==
 +
 
 +
* Get a copy of [[Media:guitar.wav | guitar.wav]]:
 +
 
 +
  getcopy guitar.wav
 +
 
 +
* Play it with '''aplay'''
 +
* Notice that it is a '''signed 16-bit''' sample wav-file.
 +
* Rewrite your program for Test #3-a, and adjust it so that it works '''correctly''' wit the 16-bit sound file. 
 +
* ''Note: you will have to modify the size of the buffer in the file '''wav.inc''' to accomodate this larger wav file''
 +
 
 +
==Test #4: Twice the Sound==
 +
 
 +
* Double up the size of the wav file, making it repeat the sound "goodbye" twice, so that you will hear "goodbye, goodbye".
 +
 
 +
 
 +
==Test #5: Adding an echo... ==
  
* Listen to the resultCan you still understand the message?
+
This will be [[CSC231 Homework 6 2010 | Homework 6]]You can start on it if you have time...
  
* Copy goodbye2.wav into goodbye.wav and repeat the process.  Still understandable?
+
<center>
 +
[[Image:CSC111 Full Echo.png|400px]]
 +
</center>
  
==Test #2==
+
* Figure out how to implement the "graphic" algorithm shown above:
* Same thing, but this time you will divide the intensity by 2. A good way to divide by two is to shift the binary pattern to the right.   When you
+
** The original sound is Sound 1 ("goodbye" )
 +
** you copy it once in a new buffer, in the same location
 +
** you copy it a second time, decreasing its amplitude and adding it to the new buffer, with an offset of about 1500.
 +
** you copy it a third time, decreasing its amplitude some more, and adding it to the new buffer, with an offset of about 3000.
 +
** you copy the new buffer back into the wav buffer, and write the file to disk...
 
<br />
 
<br />
 
<br />
 
<br />

Latest revision as of 11:06, 27 October 2010

--D. Thiebaut 13:51, 25 October 2010 (UTC)


SoundWave.jpg



This lab covers sound files in the WAV format, and performing various operations on a sound file using array operations.

The Format of Sound Files

Part 1

Get the code

or simply get them with getcopy
 getcopy readWavFileSkel.asm
 getcopy wav.inc

Get sound files

  • Get some sample wav files:
 getcopy hello.wav
 getcopy goodbye.wav
 getcopy dratcomp.wav
 getcopy force.wav
 getcopy takeover.wav
 wget http://www.duke.edu/~rfb/palace/wavs/energize.wav

Play the sound

  • Play the files with aplay to make sure you can hear them:
aplay goodbye.wav
Playing WAVE 'goodbye.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
  • Important: make a note of the size of the samples, in this case 8 bits, unsigned.

Assemble, Link and Run

  • Do not modify readWavFileSkel.asm yet. On its own it will create a new copy of the goodbye.wav under the name goodbye2.wav.


  • Assemble and link the file
nasm  -f elf readWavFileSkel.asm
ld -melf_i386 -o readWavFileSkel readWavFileSkel.o
rm goodbye2.wav
./readWavFileSkel
  • Check that you now have a new file in your directory called goodbye2.wav
  • Play it.
 aplay goodbye2.wav
(Note: on a mac, you can use afplay from the command line instead of aplay.)
You should hear the same thing as you did when listening to the goodbye.wav file.

Part 2

Test #1: Increase intensity, the simple way

  • Make a copy of readWavFileSkel.asm and call it readWavFile1.asm
  • Modify it so that you multiply the intensity of the sound by 2.
  • Listen to the result. Can you understand the message?


Test #2: Increase intensity, the more sophisticated way

  • You will have figured out that the previous method gives poor results. Instead try to figure out how we can mulitply an 8-bit sample by 2 in such a way that if the result is less than 255, we keep it as is, but if it is larger than 255, we force the sample to 255. In other words, figure out a way to implement this algorithm with the instructions you know:
     sample = buffer[ i ];
     sample = sample * 2;
     if sample > 255:
        sample = 255
  • implement your solution in you readWavFile1.asm file, assemble, link, and listen to the result... Any better?

Test #3-a: Decrease Intensity

  • Same thing, but this time you will divide the intensity by 2. A good way to divide by two is to shift the binary pattern to the right. For example, to shift right the contents of eax by one bit, do this:
         shr      eax, 1

Test #3-b: Decrease Intensity of a 16-bit Wav File

 getcopy guitar.wav
  • Play it with aplay
  • Notice that it is a signed 16-bit sample wav-file.
  • Rewrite your program for Test #3-a, and adjust it so that it works correctly wit the 16-bit sound file.
  • Note: you will have to modify the size of the buffer in the file wav.inc to accomodate this larger wav file

Test #4: Twice the Sound

  • Double up the size of the wav file, making it repeat the sound "goodbye" twice, so that you will hear "goodbye, goodbye".


Test #5: Adding an echo...

This will be Homework 6. You can start on it if you have time...

CSC111 Full Echo.png

  • Figure out how to implement the "graphic" algorithm shown above:
    • The original sound is Sound 1 ("goodbye" )
    • you copy it once in a new buffer, in the same location
    • you copy it a second time, decreasing its amplitude and adding it to the new buffer, with an offset of about 1500.
    • you copy it a third time, decreasing its amplitude some more, and adding it to the new buffer, with an offset of about 3000.
    • you copy the new buffer back into the wav buffer, and write the file to disk...