Hi Naomi,
This issue has been raised twice today, it deserves a careful answer.
The general reason why the parameters of format encoders are special
is that the type of the encoder may depend on those formats. This is
mainly (only?) the case with the channels parameters, for example
%mp3(channels=2) has type format(2,0,0) but %mp3(channels=1) has type
format(1,0,0). A type depending on a value is called a dependent type,
and integrating such things in a static type system makes things quite
complicated for users.
Now, the above explanation doesn't apply to the samplerate parameter,
but unfortunately the current language treats all format parameters in
the same way. There is however a relatively simple way to work around
this limitation, because things such as sample rates have a limited
range of values.
def mono_audio_enc(~samplerate=44100)
if samplerate==48000 then
%mp3(samplerate=48000)
elsif samplerate==44100 then
%mp3(samplerate=44100)
elsif samplerate==22050 then
%mp3(samplerate=22050)
elsif samplerate==48000 then
%mp3(samplerate=48000)
else
# There must be a default case
print("Samplerate #{samplerate} is invalid, choosing 44100Hz.")
%mp3
end
end
The important point is that all the branches return an encoding format
of the same type:
mono_audio_enc : (?samplerate:int)->format(audio=2,video=0,midi=0)
A full implementation would be longer, the full list of allowed values
being [8000;11025;12000;16000;22050;24000;32000;44100;48000]. It gets
worse when you combine this with the possibilities for bitrates, ie.
[8;16;24;32;40;48;56;64;80;96;112;128;144;160;192;224;256;320]. We
already have 9 x 18 possibilities, and even more parameters may be
taken into account... It's stupid, but that's the kind of code you can
automatically generate once and for all, and share with the world
until there is a simpler builtin solution ;)
Hope this helps,
David
------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users