Quantcast
Channel: The Audio Programming Book - cdm community
Viewing all 27 articles
Browse latest View live

Just ordered my book!


Code Snippets

$
0
0
This topic is for trading, reading and discussing snippets of code in order to gain a better understanding of C/C++/Obj C audio programming. Members are encouraged to post small programs or code excerpts, and to comment on the works of others in the form of questions and constructive criticism.
"A computing skill which is often mentioned but rarely taught is the ability to read a program and understand what it does, and how... It has been said that the teaching of computing concentrates too much on writing programs and too little on reading, unlike of literacy, where reading is usually the higher place."

— John ffitch, The Audio Programming Book (pg 581)

Up and Running

$
0
0
People are starting to receive their copies of The Audio Programming book and sinking their teeth into this dense tome of computer music knowledge. So it's time to push forward with getting this group up and running.

First, we'll need to be able to trade code.  I use gist.github.com myself, though if anyone has any alternatives, please share.  Here's an example of a small program I wrote based on Listing 1.2 by Richard Dobson:

https://gist.github.com/718095

A wiki might be in order to help catalog some of the tricks we've collectively learned or help develop here.  John ffitch, one of the book's authors, has suggested creating an errata; The wiki would be perfect for this as well.

We'll also need to create a list of support links to topics such as c/c++/obj c programming and DSP, both to sites and specific articles.  There are also many groups here at noisepages that have a definite overlap of interest. For example:

Pd Everywhere
http://noisepages.com/groups/pd-everywhere/

Digital Signal Processing
http://noisepages.com/groups/digital-signal-processing/

C and C++ Coding for Plug-ins
http://noisepages.com/groups/c-and-c-coding-for-plug-ins/

Exercise 1.2.6 - Pitch Deviation?

$
0
0
I am breezing through the book so far, I think my programming knowledge in other areas helps. My mind is for some reason boggled by this exercise 1.2.6, to calculate the percentage pitch deviation. I know the silly sort of round about way of doing it is:
 1. find the closest two midi notes
 2. get their frequencies and subtract them to get the denominator.
 3. subtract the closest midi note's frequency from the given frequency to get the numerator
 4. Divide the two to get the percentage

But I know there has to be a better way. Did anyone reading the book approach this problem?

simple pan problem

$
0
0
On page 221:
"We need a function that, given a position parameter (in the range -1 ... +1), returns two values, representing the amplitude scaling factors (range 0...1) for the left and right output channels."

The code they offer on page 222:

PANPOS simplepan(double position)
{
  PANPOS pos;
  position *= 0.5;
  pos.left = position - 0.5;
  pos.right = position + 0.5;
  return pos;
}

Do you see the problem here? The amplitude factors are supposed to be from 0...1 but this code can return negative values for the left amplitude factor.  E.g. a pan position of 0.0 (center) results in a left channel scaling of -0.5, ergo getting its phase inverted... which is exactly what I end up in my audio file after completing the example.

Is this errata material or am I just missing something here?

2.4.4 Envelope extraction

$
0
0
On page 246 this code:

/*  set buffersize to the required envelope window size */windur /= 1000.0;  /* convert to secs */winsize = (unsigned long)(windur * inprops.srate);
converts a supplied duration to a window size which is subsequently used to determine the envelope value for that sample.  
Unless I've missed something (or written the code wrong) I have discovered that as the window size gets very small windur needs to be recalculated from the window size & sample rate; otherwise the envelope produced begins to be elongated.

Has anyone else seen this?

Strange Problem with Siggen on Windows

$
0
0
All, I've encountered a strange problem with the siggen.c code in Chapter 2. For the most part everything is working fine, but if I use an amplitude value of 1.0 (or 1) on the command-line with a Sine wave output, the waveform "clip" every 4-8 cycles. If I crack open the output file in Audacity, I can take a close look and see that there is no real pattern to this clipping. The peak of the waveform, rather than hitting 1.0, is reversed and becomes -1.0, and the next sample is back near .98.

Anyway, if I use an amp value of .99, everything works fine. I suspected the "wrap-around" code in the sinetick function was causing this, but it still occurred after I commented it out and rebuilt.

Has anyone else encountered this problem on other platforms? 

CD broken, text2fs missing

$
0
0
Hi folks,

seems like this is the right place to ask and I would really appreciate if you could help me:
Today I opened the package of the CD to install text2fs on my machine. The only problem: the package somehow dissolved partly and was thereby glued to the disk itself. I tried my best to clean it and can actually read a lot of files now, but what's not working is the text2fs-program - I just can't get a running copy of it.
Would anybody be so kind and point my to a place to download it or to an alternative program for the same purpose. Or maybe someone can copy it from his/her very own disk and send it to me? I would be really glad if i could use this tool.

Thank you very much in advance!

Marc

PortMIDI Note

$
0
0
For those of you working on the PortMIDI stuff, it has been brought to my attention that the PortMIDI library included on the DVD is the 32 bit version. If you're running a 64-bit processor this will cause some problems. The newest version of PortMIDI is available up on the PortMedia website: http://portmedia.sourceforge.net/

Also, don't make the same mistake I did! I used a very simple method to "auto-detect" the MIDI device the user wants by opening every available MIDI device, listening for input on every device, and closing every other MIDI device after one picked up a message. I however made the mistake of listening for input on every MIDI device, not just the ones that were opened for input (output only devices weren't opened). This caused a crash with the NEW version of PortMIDI but the older version didn't seem to care, so I had to change a lot of my code to check to make sure the device was open before I tried to Pm_Read from it. Keep this in mind as you work through any PortMIDI examples as some of the examples in the book may crash from this same issue. You can use Pm_Poll (PortMidiStream *stream) to check whether or not a stream is available for input. This function returns TRUE, FALSE, or a PmError.

SO, to sum it up. If you're reading from a MIDI device with Pm_Read, it's probably smart to use a:
if(Pm_Poll(myStream)) Pm_Read ... etc
before you attempt to read from a stream.

Hope this saves some headaches for people.

Recommended compiler/IDE for Windows

$
0
0
Is there a recommended compiler and IDE for Windows that can be used to compile the code from the book? I believe there are a couple of options available (I'm not interested in using MS Visual C/C++).

Audio Mathematics: Appendix H++

$
0
0
I'd like to open up a new topic here to try and expand some of the Audio Mathematics section with some links, suggestions from the group, and to ask for help on occasion. Maybe John ffitch will jump in here and help as well.

DVD chapters 37-40

$
0
0
hi guys,
the book is just arrived at my place!
i've loaded the DVD and the DVD CHAP. 37-40 are just a few lines pointing to http://csounds.com/apb
but there's nothing on the site if you try to access the individual chapters.
any info?
thanks

mac os x text2sf

$
0
0
any able to get text2sf to compile on mac os x 10.6.7 ?
make returns an error : ./include/portsf.h:138: error: expected specifier-qualifier-list before ‘/’ token
which I thought meant it cant find the .h file.
i tried changing the import statement  but still fails.
would appreciate it if someone who got it working could explain how.

Chris

Can't compile a basic program with portsf on code::blocks

$
0
0
hi all, i am studying the book, and i tried to build a small program using the psf_sndOpen function from portsf library. I'm using code::blocks on ubuntu, i grabbed the four library files (from the 2nd chapter folder), put them in a folder on my hd and indicated the path in code::blocks, going in Settings->Compiler and debugger->Search directories. I did this both for linker and compiler.

Then i included portsf.h in my file, and i guess it could see it because the auto-complete feature shows names from the library while i'm writing, but when i try to compile i get these errors:

undefined reference to 'psf_init'
undefined reference to 'psf_sndOpen'
undefined reference to 'psf_finish'

I tried searching on the web and i read that i should indicate the libraries in Settings->Compiler and debugger->Linker settings as well, but it asks for .a, .so or .lib files, which i don't have.

I don't know what to do, is there anyone who uses codeblocks and can help me?

VC++ Access Denied

$
0
0
Hi all,
I've been trying to get the DFT (chapter7) example going in Visual Studio C++ (sorry), and I get an Access Denied on the command line. Also dft.exe is not a valid Win32 program. I've tried config of both 32 bit & 64 bit to no avail. I'm trying to statically link to libsndfile and have made the following VC++ settings:
• Install libsndfile to default location of C:\Program Files\Mega-Nerd
• Set up a new project, bring in header files such as sndfile.h and spec.h
• Change project’s property pages->Configuration Properties->VC++ Directories->library directories to “$(LibraryPath);C:\Program Files\Mega-Nerd\libsndfile\lib;”
• Change property pages->Configuration Properties->C/C++->General->Additional Include Directories to “C:\Program Files\Mega-Nerd\libsndfile\include;..\rfftw”
• Change project’s property pages->Configuration Properties->Linker->Input->Additional Dependencies to “libsndfile-1.lib;%(AdditionalDependencies)”
• Change project’s property pages->Configuration Properties->Linker->Input->Module Definition File to “C:\Program Files\Mega-Nerd\libsndfile\lib\libsndfile-1.def”
Thanks for any assistance!
Best wishes,
Martin.

Chapter 0 - Exercise 0.10.3 minor bug

$
0
0
Hello,
I'm currently learning C at school, so I bought a copy of The Audio Programming Book for personal study.
While doing the exercises in chapter 0, I found a small bug in the function-based interval program.
When the user enters 2 wrong notes, the program returns a unison instead of reporting the error.
While that may seem trivial to more advanced programmers, as a beginner, it got my head scrathing for some time.
I finally found a solution, then took it a step further and checked which note isn't a natural note and report that.
I think that, for beginners, this bug is a good thing as it makes for an additional exercise, but this could maybe be explicited in the text with something like a "this program has a bug, find it and solve it" exercise.
I'm deliberately not posting my solution as it may spoil other beginners from a little fun...
Have a nice, geeky, day!!

gnuplot – help with installing

$
0
0
I just got to the part in chapter 1 that uses gnuplot.  The DVD comes with a pre packaged gnuplot-4.0.  After installing it I went into the terminal and tried to run it but got an error: "Launch of "gnuplot" failed: the PowerPC architecture is no longer supported."

I was able to track down the latest gnuplot (version 4.4.4) and had trouble installing it.  The INSTALL doc describes how to do it but for an inexperienced programmer like myself, it seems daunting.  Plus it seems that the programmer that typed up the INSTALL doc was writing a post and putting their opinions.

I'm just afraid I'm going to delete something I shouldn't or change something unbeknownst to me.  If anyone can help clarify this for me, I'm running OSX 10.7.2

Thanks
GW

Erratum

$
0
0
Hi! Is there somewhere we can post or search "errata", or does MIT Press have a page somewhere for that? I found one minor typo in the source code listing on pg. 69, line 25: there's a comma and a quotation mark that are reversed.

Errata

$
0
0
is this the right place to suggest errata? I'm not far into the book, but suggest these..
0.9.2 - 'multiplication' should read 'division'
0.12.24. pointer declarations;
return-type (*pointer-name) (arguments); [ <- no square bracket at the end.
0.13 ...is a valid assignment to an int, and...
strcpy(note.name, "C" ); should read strcpy( firstnote.name, "C" );

... use of structures and how to operate on them...", The code sample, for me, 
scanf("%f%f", &re, &im ); there needs to be a space between the two '%f's

0.15  strictly speaking, isn't the program name an argv so for( i=0;... would be more correct? Hair-splitting! really.

Listing 1.9.5 in fn definition, int byte_order() line 23, I think should read
char* endptr = (char*) &one; 

IBM's site gives an succinct variation using a #define statement: 
const int i = 1;
#define is_bigendian() ( (*(char*)&i) == 0 )See: http://www.ibm.com/developerworks/aix/library/au-endianc/index.html?ca=drs-#N10168

I am not getting as much time as I would like to work through the book, so I have only got this far :-(
But, lovin' the book!!

Damaged disc

$
0
0
Bought the book last week but the little pocket which attached the disc to the back cover was incorrectly manufactured, leading the data side of the disc to be covered in glue and scratches... any way I can download the disc contents from somewhere?
Viewing all 27 articles
Browse latest View live