Greetings,
While working through Chapter 1 of the cSound book, we discovered there could be a problem with the Loscil Opcode. After double checking destination folder and buffer size, it still reported no legal base frequency, and the aif file was not played correctly until we found the correct base frequency of 440 hz and entered it as the fourth argument. It appears that the loscil opcode is having issues reading the base frequency imbedded in a file for this version of programs.
Csound 5.08 OSX 10.4-PPC
MacCsound 1.3b4
Files used: sing.aif from the cSound catalog, as well as several of my own files saved using Peak Pro 5.2
Thanks!
-Roston



Works for me
-- as the saying goes
Under Linux with Csound 5.08, I tried a short test, with the relevant lines in the orc:
a1 loscil 30000, 440, 1
out a1
and the function table in the sco:
f1 0 0 1 "sing.aif" 0 0 0
Reproduced the "Laaa" sound fine.
I wonder if you have the right '
sing.aif'? I don't have the Csound Catalog, but I found mine in class materials for a Csound course somewhere on the web. You do know that AIFF files can have different capabilities? [I didn't, until I started looking at this! (:-)] 'loscil' wants an "instrument" type AIFF for it to work with minimal parameters. The sing.aif I downloaded is such a file, with a "base note" of '69' ("A") -- i.e. 440 Hz. If, however, the file doesn't have the requisite 'INST' chunk you'll get problems much as you described.For comparison, the file I have is 204190 bytes in size. Csound5 actually neatly lists the file parameters when it loads it, so you should be able to see things like "Base Note : 69" in the output.
Regardless of all that, the documentation for loscil is indubitably a mess... That single opcode has caused me more screaming than any other. Nowhere, for a start, does it mention that all those "optional" parameters will only actually be supplied by those special "Instrument" AIFF files. I spent a couple of days trying to figure out why the WAV file I had wouldn't play! And why I couldn't add loop points to it...
The deal with oscil...
Hey Roston, it's Fede, from your Csound class....
I hadn't really looked into the loscil thing until today. So, anyways, here's the deal (I'll keep it as simple as possible):
An AIFF file is made up of various chunks of data:
Common Chunk
Sound Data Chunk
Marker Chunk
Instrument Chunk
Comment Chunk
Name Chunk
Author Chunk
Copyright Chunk
Annotation Chunk
Application Specific Chunk
MIDI Data Chunk
Audio Recording Chunk
Now, out of these, only the Common and Sound Data chunks are mandatory. These basically make up a standard audio file that contains, well.... audio samples.
The problem is that loscil is a table-lookup (wavetable) oscilator. This means all it does is it cycles through an array (created by GEN1) "playing" each sample in the array's locations one at a time. To do this, loscil needs to keep an internal reference frequency, so it knows at what "speed" the sample sounds unaltered, and also to calculate frequency changes (if you alter the pitch of the original file from csound).
Now, loscil gets this base (reference) frequency from an AIFF file's instrument chunck. The problem is that the AIFF spec says that, but for the two chunks I already mentioned, all other are optional. So, unless you use some soft that you know specifically writes this instrument chunk to the file, you basically might or might not be able to use the file with loscil. When loscil complains that there's no valid base frequency, basically it's looking for the instrument chunk in the the AIFF file and can't find it, and so it plays the sample at whatever rate it's coded to do so by default.
Whether this is a bug or not is somewhat debatable. personally I think, programmer-wise, that your software should not assume anything unless it's mandatory in a spec. Doing so, makes for sloppy soft (which is sort of the case here).
Now, there's two solutions to this:
1. modify some parts in the source code of loscil so that it doesn't assume anything and allows the user to specify the base frequency.
2. make sure your AIFF files have an instrument chunk that conforms to the AIFF spec.
I first tried ner 1, but, honestly, the code is a mess........ it basically goes against all "software best practices" that you are taught at school. So, personally, I don't find a bit of amusement in touching that code.
So I went for ner 2. Basically, I coded a little silly app, and the way it works is:
1. you supply it with an AIFF file.
2. it checks if the instrument chunk is present in the file.
3. if the chunk is there, it just tells you so, and does nothing to the file.
4. if the chunk is not present, the program adds an instrument chunk to the AIFF file, with a dummy frequency of A4 (so if you want to play the file at normal pitch in csound, you just tell loscil 440 for the frequency argument).
I don't know, I personally think this workaround shouldn't be necessary in the first place, but oh well.....it works. I used this for my 3 samples for the etude1 and it they play just fine now.
If you, or the class, or anyone wants this little program, just let me know.
Hope this helps. Excuse me if I sound sort of weird, it's 3.30am and I can't even stare straight at the screen.
It's not that hard... (:-)
'Fede', most of what you say is accurate, but you've actually complicated things a bit more than they need to be.
The main thing is that the "base frequency" in that Instrument Chunk really has nothing to do with the actual rate at which the sound is played back. That's normally determined by the (non-optional) Sample Rate encoded in the file, and in the absence of anything else, the audio should come out exactly as it was recorded. The Base Frequency is just an indication of the original pitch of the recorded sound, in case you want to change it.
The problem is that loscil is intended to be a variable pitch source, so it wants a base frequency to compare with the supplied desired 'kcps', so it can make the needed adjustment. If there's an Instrument Chunk to provide it, that's what it will use. However if that chunk is absent, you're not really in any trouble at all; you just provide the base as the fourth parameter 'ibas'.
There's no need to generate a special AIFF file. If -- as for 'sing.aiff' -- the base note is 'A' (which is actually what would be in the INST chunk -- not the frequency), just set ibas = 440 and everything should be fine.
I totally agree with you though about the source code... ugh! I think if one wanted to fix the (several) problems with loscil it would be best simply to start afresh with a new opcode. (Which would also avoid the possibility of breaking older stuff.)
Pete, thanks for the info!
Pete, thanks for the info!
I guess it was 3 am and I just skipped over the optional arguments... I never realized there was an ibas parameter in the first place.
Yeah, if there's ibas, then there's no need to add the instrument chunk to the file itself.
The one thing that I don't get is, you are telling me the instrument chunk has nothing to do with the actual rate at which the sound is played back. I don't know if I'm misunderstanding you, but I know that. That's why I said loscil should allow its client to supply a base frequency (which it does, only I didn't know). I also said that "loscil" uses the base note in the instrument chunk for the base frequency (which it does).
I didn't say that wavetable oscillators in general need an instrument chunk, or that the base note member of the instrument chunk in an AIFF actually determines anything (one of the first things I said was that this chunk is optional).
Anyways, please don't take it the wrong way. I'm seriously just restating what I said and asking if there's anything I misunderstood.
Thanks again for the info on the ibas argument!
Sorry -- wasn't trying to correct you
It's just a bit hard, when writing in a hurry, to make sure one has got the desired points across. I thought I needed to (re-)include the stuff about base frequency to make it coherent. Apologies if that sounded like I thought you had it wrong!
And I should have mentioned that I thought it pretty cool that you whipped up an AIFF rewriter, in any case... (:-))
yeah it's cool...
yeah it's cool... seriously.
I just really wanted to know if I was messing up, cause I re-read my original post and still didn't find that much of a difference with what u said.
Thanks again!