Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: a cvt_float_to_linear question (Read 5650 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

a cvt_float_to_linear question

a cvt_float_to_linear question:
how a sample with type "audio_sample"(default is 64-bits double) convert to 16-bits integer type(short)?

audio_sample d;
short s;

it should be:
(1) s = (short)d;
or
(2) s = (short)(d >= 0.5 ? d + 0.5 : d - 0.5);
or other?

Is there any audible difference?

a cvt_float_to_linear question

Reply #1
No. See ff123's page about dithering. It's impossible to hear the difference in normal circumstances.

You also want to read up a bit about rounding on the x86 architecture. You might be surprised how awfully slow the above code runs.

a cvt_float_to_linear question

Reply #2
Please allow me demonstrate my ignorance as a newbie to digital audio...

My understanding is that audio_sample is in the range -1 to +1. So I would expect case (1) to yeild zero most of the time, and case (2) to be zero %50 of the time and 1 the ofther 50% of the time. Doesn't the audio_sample need to be scaled by the number of bits, i.e.

s = (short)(d*32768) ?

Thanks for the help!

Dave

 

a cvt_float_to_linear question

Reply #3
From your current discussion, it would appear you are trying to replace the functionality of cvt_float_to_linear. This service is currently a part of the core, so it is not possible to replace it. Even if you were to register your own cvt_float_to_linear service, the core service would have a higher priority, so nothing would ever see your service.

a cvt_float_to_linear question

Reply #4
I need to transfer from double to short int, so i use cvt_float_to_linear function in my on_chunk message function. But I found that my memory is eaten by calling cvt_float_to_linear function...

Is there anything I forgot to do?  >_<~~~

my code(on_chunk):

   static output_chunk si_chunk;
   cvt_float_to_linear::get()->run(chunk,&si_chunk,16,0,0);
   chunk->set_data_fixedpoint_signed((short int*)si_chunk.data,si_chunk.size,si_chunk.srate,si_chunk.nch,si_chunk.bps);

a cvt_float_to_linear question

Reply #5
You do not need to declare that output_chunk as static, but you do need to cache the handle to that cvt_float_to_linear service and release it when you are done.

cvt_float_to_linear * cvt;

constructor() : cvt(0) {}
~destructor() { if (cvt) cvt->service_release(); }

on_chunk() {
output_chunk si_chunk;
if (!cvt) cvt = cvt_float_to_linear::get();
cvt->run(chunk, &si_chunk, 16, 0, 0);
chunk->set_data_fixedpoint_signed(blah);
}

I may be wrong with this pseudo-code, it's been a while since I've messed with this service, and I'm also a bit tired at the moment.


Note that you do not need to maintain the buffer that you pass to the chunk, it allocates its own buffer and copies the samples. In fact, you can also use check/set size functions on it to allocate the buffer, which you can also write to, in cases where you are rendering directly to the chunk in the native audio_sample format. Dig around the SDK.

Oh, and what are you doing? You appear to be downsampling to 16 bits per sample, then calling the chunk function which then upsamples back to the audio_sample format, 64-bit floats.

a cvt_float_to_linear question

Reply #6
Thank you Kode54~~~

Our Plugin has been finished!
this plugin can make DFX plugin(for winamp) to work under foobar.

It is my first time write program under a big framework of project like this.
Thank you very much   

p.s. download plugin

a cvt_float_to_linear question

Reply #7
  • I see the path to the DFX component is partially hardcoded. You could be retrieving this from the registry. You could also turn this into a generic Winamp DSP wrapper.
  • I see a hard coded path of d:\pluglog.txt in the component. You could be using the console service to log info/warnings/error messages. See console.h.

a cvt_float_to_linear question

Reply #8
Foobar2000 fails to load the plugin (foo_dsp_Foobar2WinampPlugin.dll) here though all required files are in the components directory (msvcr71.dll, dsp_dfx.dll + folder).
Do I miss sth.?

a cvt_float_to_linear question

Reply #9
It appears to be hardcoded to expect the DFX plug-in to be in its default installation folder. It doesn't appear to check the registry for the actual location, or allow for the current directory.

The path is:

(unknown base, probably Program Files)\dfx components\dfx installation\Plugins\dsp_dfx.dll

a cvt_float_to_linear question

Reply #10
to [kode45]:
  thanks. I will fix it~~
  I am still studying the code and interface of foobar. Maybe the code used in my plugin is not the most proper code, but I will keep studying 

to [the link]:
  Can you show some error message for me?  ^^
 
  foobar\component\:
      1. msvcr71.dll
      2. foo_dsp_Foobar2WinampPlugin.dll

  foobar\component\DFX Installation\plugins\:
      1. dsp_dfx.dll
      2. [folder] dsp

  so, you can just install DFX in any place, then cut & paste the folder "DFX Installation" to foobar\component\
 

  p.s. the version of DFX in my test is 7.0

a cvt_float_to_linear question

Reply #11
Ahhh ... my fault! It works now.
I didn't copy  "DFX Installation\plugins\" but just "dsp_dfx.dll" and "dsp" folder to the components folder.

Regards,
The Link

a cvt_float_to_linear question

Reply #12
Quote
to [kode45]:
  thanks. I will fix it~~
  I am still studying the code and interface of foobar. Maybe the code used in my plugin is not the most proper code, but I will keep studying 

to [the link]:
  Can you show some error message for me?  ^^
 
  foobar\component\:
      1. msvcr71.dll
      2. foo_dsp_Foobar2WinampPlugin.dll

  foobar\component\DFX Installation\plugins\:
      1. dsp_dfx.dll
      2. [folder] dsp

  so, you can just install DFX in any place, then cut & paste the folder "DFX Installation" to foobar\component\
 

  p.s. the version of DFX in my test is 7.0
[a href="index.php?act=findpost&pid=242390"][{POST_SNAPBACK}][/a]



As soon as foo_dsp_Foobar2WinampPlugin.dll is in my component folder, foobar2000 does not start anymore - or exactly: it starts and closes itself in one second.

Claus

a cvt_float_to_linear question

Reply #13
what version of foo_dsp_foobar2winampPlugin do you use?
(20040918 or 20040919)

please tell me, and I will find out the source of problem for you.  ^^

p.s. my msn account is samuelcdf@hotmail.com. Welcome to chat ~

a cvt_float_to_linear question

Reply #14
Quote
what version of foo_dsp_foobar2winampPlugin do you use?
(20040918 or 20040919)

please tell me, and I will find out the source of problem for you.  ^^

p.s. my msn account is samuelcdf@hotmail.com. Welcome to chat ~
[a href="index.php?act=findpost&pid=243008"][{POST_SNAPBACK}][/a]


The newer Version. But suddenly, after another reboot,it worked. Don't know what happend, but I can't reproduce the error 

Claus