Csound Csound-dev Csound-tekno Search About

event opcode and more....

Date2006-05-03 14:02
FromRory Walsh
Subjectevent opcode and more....
I was just wondering if I have gone about this ass ways or not. It works 
fine, but I would like to know if there is a better way of doing it? I 
want to create an instrument that will play a sound file that's passed 
as a string on start-up. I then grab the length of the sound file and 
trigger an instrument to play for that length of time. Basically I don't 
want to have to be messing around with the instrument once it's done, 
it's for a simple sound file player. Here's the code:



//defualt options
-odac --strset1=D:/MyDocuments/csoundfiles/rory.wav


sr = 44100
kr = 4410
ksmps = 10
nchnls = 2

instr 1
Sname strget 1
strset 10, Sname
gitemp ftgen 1, 0, 0, 1, Sname, 0, 0, 0
ilen  filelen "D:/MyDocuments/csoundfiles/rory.wav"
event_i "i", 2, 0, ilen
endin

instr 2
Sname strget 10
a1, a2 soundin Sname
out a1, a2
endin



i1 0 1


Date2006-05-03 14:24
FromDavid Akbari
SubjectRe: event opcode and more....
Hi Rory,

I suggested something similar to the blue list some time ago as a sound 
file mechanism... the idea is this; since long before there were Stype 
variables in the API, we have had to deal with strings. You guys have 
already discussed several good ways to deal with this issue, however 
omitting one crucial and particularly effective mechanism in the Csound 
language - macro definitions. I often enjoy using a solution like [0] 
to deal with indexing soundfiles. The bonus over diskin or some other 
such is to have explicit control over the sample index, similar to how 
Victor mentioned a constant kndx value to the pvsfread opcode as a 
technique for "spectral freezing".



-David

[0]




sr		=	44100
kr		=	441
ksmps	=	100
nchnls	=	2

#define	TEHFILE	# "/loops/dl_break0.aif" #

/*--- ---*/

		instr	1

itabsz	filelen	$TEHFILE.

itmp	ftgen	1, 0, (itabsz * sr), 1, $TEHFILE., 0, 4, 0

andx	phasor	(1 / itabsz)
andx	=	andx * (itabsz * sr)

a1	table	andx, 1
a1	=	a1 * 32767 ; or 0dBFS

	outs	a1, a1

		endin

/*--- ---*/


i1	0	10

e






On May 3, 2006, at 9:02 AM, Rory Walsh wrote:

> I was just wondering if I have gone about this ass ways or not. It 
> works fine, but I would like to know if there is a better way of doing 
> it? I want to create an instrument that will play a sound file that's 
> passed as a string on start-up. I then grab the length of the sound 
> file and trigger an instrument to play for that length of time. 
> Basically I don't want to have to be messing around with the 
> instrument once it's done, it's for a simple sound file player. Here's 
> the code:
>
> 
> 
> //defualt options
> -odac --strset1=D:/MyDocuments/csoundfiles/rory.wav
> 
> 
> sr = 44100
> kr = 4410
> ksmps = 10
> nchnls = 2
>
> instr 1
> Sname strget 1
> strset 10, Sname
> gitemp ftgen 1, 0, 0, 1, Sname, 0, 0, 0
> ilen  filelen "D:/MyDocuments/csoundfiles/rory.wav"
> event_i "i", 2, 0, ilen
> endin
>
> instr 2
> Sname strget 10
> a1, a2 soundin Sname
> out a1, a2
> endin
> 
>
> 
> i1 0 1
> 
> 

Date2006-05-03 14:34
FromRory Walsh
SubjectRe: event opcode and more....
Yup, that's very straightforward also. I had avoided creating tables to 
make things a little more efficient, for example what if someone want to 
load a one hour piece of music to a table? Not a good idea, or maybe I'm 
wrong. Cheers,

Rory.


David Akbari wrote:
> Hi Rory,
> 
> I suggested something similar to the blue list some time ago as a sound 
> file mechanism... the idea is this; since long before there were Stype 
> variables in the API, we have had to deal with strings. You guys have 
> already discussed several good ways to deal with this issue, however 
> omitting one crucial and particularly effective mechanism in the Csound 
> language - macro definitions. I often enjoy using a solution like [0] to 
> deal with indexing soundfiles. The bonus over diskin or some other such 
> is to have explicit control over the sample index, similar to how Victor 
> mentioned a constant kndx value to the pvsfread opcode as a technique 
> for "spectral freezing".
> 
> 
> 
> -David
> 
> [0]
> 
> 
> 
> 
> sr        =    44100
> kr        =    441
> ksmps    =    100
> nchnls    =    2
> 
> #define    TEHFILE    # "/loops/dl_break0.aif" #
> 
> /*--- ---*/
> 
>         instr    1
> 
> itabsz    filelen    $TEHFILE.
> 
> itmp    ftgen    1, 0, (itabsz * sr), 1, $TEHFILE., 0, 4, 0
> 
> andx    phasor    (1 / itabsz)
> andx    =    andx * (itabsz * sr)
> 
> a1    table    andx, 1
> a1    =    a1 * 32767 ; or 0dBFS
> 
>     outs    a1, a1
> 
>         endin
> 
> /*--- ---*/
> 
> 
> i1    0    10
> 
> e
> 
> 
> 
> 
> 
> 
> On May 3, 2006, at 9:02 AM, Rory Walsh wrote:
> 
>> I was just wondering if I have gone about this ass ways or not. It 
>> works fine, but I would like to know if there is a better way of doing 
>> it? I want to create an instrument that will play a sound file that's 
>> passed as a string on start-up. I then grab the length of the sound 
>> file and trigger an instrument to play for that length of time. 
>> Basically I don't want to have to be messing around with the 
>> instrument once it's done, it's for a simple sound file player. Here's 
>> the code:
>>
>> 
>> 
>> //defualt options
>> -odac --strset1=D:/MyDocuments/csoundfiles/rory.wav
>> 
>> 
>> sr = 44100
>> kr = 4410
>> ksmps = 10
>> nchnls = 2
>>
>> instr 1
>> Sname strget 1
>> strset 10, Sname
>> gitemp ftgen 1, 0, 0, 1, Sname, 0, 0, 0
>> ilen  filelen "D:/MyDocuments/csoundfiles/rory.wav"
>> event_i "i", 2, 0, ilen
>> endin
>>
>> instr 2
>> Sname strget 10
>> a1, a2 soundin Sname
>> out a1, a2
>> endin
>> 
>>
>> 
>> i1 0 1
>> 
>> 
> 

Date2006-05-03 18:32
FromDavid Akbari
SubjectRe: event opcode and more....
Hi Rory,

Yes, I see your point about potential problematic behavior that may 
result from loading extremely large files into RAM. Still, it may be 
possible to use macros effectively for a streaming from disk solution 
such as [1].



-David

[1]




sr		=    44100
kr		=    441
ksmps	=    100
nchnls	=    2

#define    TEHFILE    # "/loops/sup2_abreak16" #

/*--- ---*/

         instr    1

ichnls	filenchnls	$TEHFILE.

   if	(ichnls <= 1) then

a1	diskin2	$TEHFILE., 1, 0, 1
a2	=	a1

elseif	(ichnls > 1 && ichnls <= 2) then

a1, a2	diskin2	$TEHFILE., 1, 0, 1

else

/* deal with multichannel; quad, 5.1, ambisonics B-format, etc here */

   endif

     outs    a1, a2

        endin

/*--- ---*/



i1    0    10

e






On May 3, 2006, at 9:34 AM, Rory Walsh wrote:

> Yup, that's very straightforward also. I had avoided creating tables 
> to make things a little more efficient, for example what if someone 
> want to load a one hour piece of music to a table? Not a good idea, or 
> maybe I'm wrong. Cheers,
>
> Rory.
>
>
> David Akbari wrote:
>> Hi Rory,
>> I suggested something similar to the blue list some time ago as a 
>> sound file mechanism... the idea is this; since long before there 
>> were Stype variables in the API, we have had to deal with strings. 
>> You guys have already discussed several good ways to deal with this 
>> issue, however omitting one crucial and particularly effective 
>> mechanism in the Csound language - macro definitions. I often enjoy 
>> using a solution like [0] to deal with indexing soundfiles. The bonus 
>> over diskin or some other such is to have explicit control over the 
>> sample index, similar to how Victor mentioned a constant kndx value 
>> to the pvsfread opcode as a technique for "spectral freezing".
>> -David
>> [0]
>> 
>> 
>> sr        =    44100
>> kr        =    441
>> ksmps    =    100
>> nchnls    =    2
>> #define    TEHFILE    # "/loops/dl_break0.aif" #
>> /*--- ---*/
>>         instr    1
>> itabsz    filelen    $TEHFILE.
>> itmp    ftgen    1, 0, (itabsz * sr), 1, $TEHFILE., 0, 4, 0
>> andx    phasor    (1 / itabsz)
>> andx    =    andx * (itabsz * sr)
>> a1    table    andx, 1
>> a1    =    a1 * 32767 ; or 0dBFS
>>     outs    a1, a1
>>         endin
>> /*--- ---*/
>> 
>> 
>> i1    0    10
>> e
>> 
>> 
>> On May 3, 2006, at 9:02 AM, Rory Walsh wrote:
>>> I was just wondering if I have gone about this ass ways or not. It 
>>> works fine, but I would like to know if there is a better way of 
>>> doing it? I want to create an instrument that will play a sound file 
>>> that's passed as a string on start-up. I then grab the length of the 
>>> sound file and trigger an instrument to play for that length of 
>>> time. Basically I don't want to have to be messing around with the 
>>> instrument once it's done, it's for a simple sound file player. 
>>> Here's the code:
>>>
>>> 
>>> 
>>> //defualt options
>>> -odac --strset1=D:/MyDocuments/csoundfiles/rory.wav
>>> 
>>> 
>>> sr = 44100
>>> kr = 4410
>>> ksmps = 10
>>> nchnls = 2
>>>
>>> instr 1
>>> Sname strget 1
>>> strset 10, Sname
>>> gitemp ftgen 1, 0, 0, 1, Sname, 0, 0, 0
>>> ilen  filelen "D:/MyDocuments/csoundfiles/rory.wav"
>>> event_i "i", 2, 0, ilen
>>> endin
>>>
>>> instr 2
>>> Sname strget 10
>>> a1, a2 soundin Sname
>>> out a1, a2
>>> endin
>>> 
>>>
>>> 
>>> i1 0 1
>>> 
>>> 

Date2006-05-03 21:10
FromJean-Pierre Lemoine
SubjectRe: event opcode and more.... table size
Hi David,
I was just looking for such a code (looping a file from a table), but 
never find a nice solution as the length of the table must be a power of 
two.
"itmp    ftgen    1, 0, (itabsz * sr), 1, $TEHFILE., 0, 4, 0" gives an 
error  if  itabse * sr is not a power of two. From the manual if a 
length of zero is specified, the entire file is read in memory but we 
must use loscil.
Thus did I miss something? Is there an easy way for specifying the table 
size (a power of two greater than the number of points in the file) and 
keep the use of phasor   ?

Jean-Pierre

David Akbari wrote:
> Hi Rory,
>
> I suggested something similar to the blue list some time ago as a 
> sound file mechanism... the idea is this; since long before there were 
> Stype variables in the API, we have had to deal with strings. You guys 
> have already discussed several good ways to deal with this issue, 
> however omitting one crucial and particularly effective mechanism in 
> the Csound language - macro definitions. I often enjoy using a 
> solution like [0] to deal with indexing soundfiles. The bonus over 
> diskin or some other such is to have explicit control over the sample 
> index, similar to how Victor mentioned a constant kndx value to the 
> pvsfread opcode as a technique for "spectral freezing".
>
>
>
> -David
>
> [0]
>
> 
> 
>
> sr        =    44100
> kr        =    441
> ksmps    =    100
> nchnls    =    2
>
> #define    TEHFILE    # "/loops/dl_break0.aif" #
>
> /*--- ---*/
>
>         instr    1
>
> itabsz    filelen    $TEHFILE.
>
> itmp    ftgen    1, 0, (itabsz * sr), 1, $TEHFILE., 0, 4, 0
>
> andx    phasor    (1 / itabsz)
> andx    =    andx * (itabsz * sr)
>
> a1    table    andx, 1
> a1    =    a1 * 32767 ; or 0dBFS
>
>     outs    a1, a1
>
>         endin
>
> /*--- ---*/
> 
> 
> i1    0    10
>
> e
> 
>
> 
>