Jump to content

256a-fall-2017/hw1: Difference between revisions

From CCRMA Wiki
Ge (talk | contribs)
Created page with "= Homework #1: Real-time Audio: Buffers, Callbacks, Waveforms = Due date: 2017.10.3 11:59:59pm, Tuesday. <div style="text-align: left;">Image:ingredients.jpg</div> Let's..."
 
Lja (talk | contribs)
 
(28 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Homework #1: Real-time Audio: Buffers, Callbacks, Waveforms =
= Homework #1: Cookin' with Low-level Audio =


Due date: 2017.10.3 11:59:59pm, Tuesday.
Due date: 2017.10.3 11:59:59pm, Tuesday.
Line 5: Line 5:
<div style="text-align: left;">[[Image:ingredients.jpg]]</div>
<div style="text-align: left;">[[Image:ingredients.jpg]]</div>
Let's get cookin'.
Let's get cookin'.


=== Specification (part 1 of 4): Real-time Audio ===
=== Specification (part 1 of 4): Real-time Audio ===
* create a program that is capable of real-time audio input/output
* create a program that is capable of real-time audio input/output
* give it name (e.g., sig-gen; creative names are always welcome)
* give it name (e.g., sig-gen; creative names are always welcome)
** start with this very basic [http://ccrma.stanford.edu/courses/256a-fall-2017/code/HelloSine] For an simple introduction to makefiles, check out this [http://linuxdevcenter.com/lpt/a/1426 link]
** start with this basic boilerplate: [http://ccrma.stanford.edu/courses/256a-fall-2017/code/HelloSine-boilerplate.zip HelloSine]
* next, add real-time audio support, using the [http://www.music.mcgill.ca/~gary/rtaudio/ RtAudio] Library (version 4.0.10 or later)
* next, add real-time audio support, using the [http://www.music.mcgill.ca/~gary/rtaudio/ RtAudio] Library (version 4.0.10 or later, included in the boilerplate)
** even though it's useful to briefly look through the package, the only files you'll need are:
** even though it's useful to briefly look through the package, the only files you'll need are:
*** RtAudio.h (the header file for RtAudio, it contains the class definitions)
*** RtAudio.h (the header file for RtAudio, it contains the class definitions)
Line 20: Line 19:
* the overall behavior when you run the program should be a continuous sine tone at 440hz...
* the overall behavior when you run the program should be a continuous sine tone at 440hz...
* to quit: press '''enter'''
* to quit: press '''enter'''
See [[Signal generator hints]] if needed.


=== Specification (part 2 of 4): Waveforms ===
=== Specification (part 2 of 4): Waveforms ===
* modify your program to take command line arguments and generate different signals, depending the command line flag you specify:
* modify your program to take command line arguments and generate different signals, depending on the command line flag you specify:


     sig-gen [type] [frequency] [width]
     sig-gen [type] [frequency] [width]
         [type]: --sine | --pulse | --noise | --impulse
         [type]: --sine | --noise | --impulse | --pulse
         [frequency]: (a number > 0, no applicable to noise)
         [frequency]: (a number > 0, not applicable to noise)
         [width]: pulse width (only applicable to pulse)
         [width]: pulse width (only applicable to pulse)


* where the flags correspond to the following signals:
* where the flags correspond to the following signals:
** --sine : sine wave
** --sine : sine wave
** --pulse : rectangular pulse wave, the width ([0.0-1.0]) controls the pulse width (e.g., width=.5 should result in a square wave)
** --noise : white noise
** --noise : white noise
** --impulse : impluse train, the frequency should determine the impulse train's fundamental period
** --impulse : impluse train, the frequency should determine the impulse train's fundamental period
** --pulse : rectangular pulse wave, the width ([0.0-1.0]) controls the pulse width (e.g., width=.5 should result in a square wave)
* it might be a good idea to output the usage (as show above), if insufficient or incorrect parameters are given
* it might be a good idea to output the usage (as show above), if insufficient or incorrect parameters are given
* you'll need to implement a simple command line parser, with basic error checking (e.g., what to do when invalid/irrelevant parameters are provided?)
* you'll need to implement a simple command line parser, with basic error checking (e.g., what to do when invalid/irrelevant parameters are provided?)
Line 42: Line 44:
=== Specification (part 3 of 4): One Ring to Modulate Them All ===
=== Specification (part 3 of 4): One Ring to Modulate Them All ===
* Next, add another command line flag:
* Next, add another command line flag:
**  --input : mic/line input (make sure to enable it in the code when initializing RtAudio)
**  --input : mic/line input (make sure input is enabled in the RtAudio initialization)
* if specified, this flag tells the program to take the mic/line input and and multiply it against the signal being generated, and output the result!
* if specified, this flag tells the program to take the mic/line input and and multiply it against the signal being generated, and output the result;
 
* test it by talking into it and listening to the result...


=== Specification (part 4 of 4): add ChucK! ===
=== Specification (part 4 of 4): add ChucK! ===
* Lastly, added ChucK as a module to your program
* Lastly, add ChucK as a module to your program
* download this boilerplate project that includes ChucK (as library and API)
* download [https://ccrma.stanford.edu/courses/256a-fall-2017/code/charles-boilerplate.zip charles boilerplate project] that includes ChucK as library and API
* modeled after this, add ChucK to your program (or alternately, replace charles.cpp with your .cpp file, and modify the top-level makefile accordingly!)
* in host/charles.cpp, add in your existing code from earlier parts
* study chuck.h in core/, everything you'd need to do is done with this file:
* study chuck.h in core/ -- it contains the chuck API you'll use to add ChucK as a module
* make the following modifications to charles.cpp (after you've brought in your code, and verified it still compiles/works):
** instantiate a ChucK object
** instantiate a ChucK object
** set parameters
** set parameters
** initialize the ChucK object (initialize(...))
** initialize the ChucK object (init())
** compile one or more files (e.g., as specified from the command line)
** compile a chuck program (created as a string, according to the specification from the command line)
** start ChucK
** start ChucK
** very importantly, drive chuck from your callback function
** very importantly, drive chuck from your callback function
* write a few short ChucK programs to verify the signals your generated in parts 2 and 3
* add the --chuck flag to your program. when it is passed in, you should generate and use a chuck program for the sig-gen functionality, rather than what you wrote in earlier parts
** sine
** sine
** pulse wave
** pulse wave
Line 63: Line 66:
** impulse train
** impulse train
** ring modulating
** ring modulating


=== Note ===
=== Note ===
* have fun with it!!!
* have fun with it!!!
* your code should compile and run on the CCRMA machines
* comment your code!
* comment your code!
* choose your own coding conventions - but '''be consistent'''
* choose your own coding conventions - but '''be consistent'''
Line 75: Line 76:
** how much error-checking and error-reporting on the command line arguments?
** how much error-checking and error-reporting on the command line arguments?


=== Hints for ChucK Code ===
[https://ccrma.stanford.edu/courses/256a-fall-2014/code/hw1/ ChucK code for reference]


 
You may want to use a [http://www.cplusplus.com/reference/sstream/stringstream/stringstream/ stringstream] or other string formatting techniques to construct ChucK programs on-the-fly
=== Testing Audio Output===
[https://ccrma.stanford.edu/courses/256a-fall-2014/code/hw1/ ChucK code for reference]


=== Deliverables ===
=== Deliverables ===
Line 85: Line 86:


* 1) Create a zip/tar file and put all the files in there. The required files are:
* 1) Create a zip/tar file and put all the files in there. The required files are:
** source code to the project (*.h, *.cpp, *.c makefile, etc.)
** source code to the project (*.h, *.cpp, makefile, etc.)
** a short README text section that:
** a short README text section that:
*** instructions on building the project (for example, anyone in the class should be able to download
*** instructions on building the project (for example, anyone in the class should be able to download
Line 91: Line 92:
*** describes any difficulties you encountered in the process
*** describes any difficulties you encountered in the process
*** lists any collaborators
*** lists any collaborators
* 2) upload zip/tar file to coursework!
* 2) upload zip/tar file to Canvas!

Latest revision as of 22:58, 29 September 2017

Homework #1: Cookin' with Low-level Audio

Due date: 2017.10.3 11:59:59pm, Tuesday.

Let's get cookin'.

Specification (part 1 of 4): Real-time Audio

  • create a program that is capable of real-time audio input/output
  • give it name (e.g., sig-gen; creative names are always welcome)
  • next, add real-time audio support, using the RtAudio Library (version 4.0.10 or later, included in the boilerplate)
    • even though it's useful to briefly look through the package, the only files you'll need are:
      • RtAudio.h (the header file for RtAudio, it contains the class definitions)
      • RtAudio.cpp (the implementation)
      • RtError.h (header containing various error handling constructs for RtAudio)
    • it may be useful to browse the RtAudio documentation and the example programs in the RtAudio distribution
  • implement the callback function to generate the expect number of samples per call for a sine wave at 440Hz
  • the overall behavior when you run the program should be a continuous sine tone at 440hz...
  • to quit: press enter

See Signal generator hints if needed.

Specification (part 2 of 4): Waveforms

  • modify your program to take command line arguments and generate different signals, depending on the command line flag you specify:
    sig-gen [type] [frequency] [width]
        [type]: --sine |  --noise | --impulse | --pulse
        [frequency]: (a number > 0, not applicable to noise)
        [width]: pulse width (only applicable to pulse)
  • where the flags correspond to the following signals:
    • --sine : sine wave
    • --noise : white noise
    • --impulse : impluse train, the frequency should determine the impulse train's fundamental period
    • --pulse : rectangular pulse wave, the width ([0.0-1.0]) controls the pulse width (e.g., width=.5 should result in a square wave)
  • it might be a good idea to output the usage (as show above), if insufficient or incorrect parameters are given
  • you'll need to implement a simple command line parser, with basic error checking (e.g., what to do when invalid/irrelevant parameters are provided?)
  • you'll also need to organize your code a bit, to selectively generate the request signal

See Signal generator hints if needed.

Specification (part 3 of 4): One Ring to Modulate Them All

  • Next, add another command line flag:
    • --input : mic/line input (make sure input is enabled in the RtAudio initialization)
  • if specified, this flag tells the program to take the mic/line input and and multiply it against the signal being generated, and output the result;
  • test it by talking into it and listening to the result...

Specification (part 4 of 4): add ChucK!

  • Lastly, add ChucK as a module to your program
  • download charles boilerplate project that includes ChucK as library and API
  • in host/charles.cpp, add in your existing code from earlier parts
  • study chuck.h in core/ -- it contains the chuck API you'll use to add ChucK as a module
  • make the following modifications to charles.cpp (after you've brought in your code, and verified it still compiles/works):
    • instantiate a ChucK object
    • set parameters
    • initialize the ChucK object (init())
    • compile a chuck program (created as a string, according to the specification from the command line)
    • start ChucK
    • very importantly, drive chuck from your callback function
  • add the --chuck flag to your program. when it is passed in, you should generate and use a chuck program for the sig-gen functionality, rather than what you wrote in earlier parts
    • sine
    • pulse wave
    • white noise
    • impulse train
    • ring modulating

Note

  • have fun with it!!!
  • comment your code!
  • choose your own coding conventions - but be consistent
  • you are welcome to work together, but you must do/turn in your own work (you'll likely get more out of it this way)
  • some considerations:
    • how to organize the code for the various types of signals?
    • how much error-checking and error-reporting on the command line arguments?

Hints for ChucK Code

ChucK code for reference

You may want to use a stringstream or other string formatting techniques to construct ChucK programs on-the-fly

Deliverables

turn in all files + readme through coursework

  • 1) Create a zip/tar file and put all the files in there. The required files are:
    • source code to the project (*.h, *.cpp, makefile, etc.)
    • a short README text section that:
      • instructions on building the project (for example, anyone in the class should be able to download
      • conveys your ideas/comments in constructing each program
      • describes any difficulties you encountered in the process
      • lists any collaborators
  • 2) upload zip/tar file to Canvas!