reaper-oss / sws

The SWS extension is a collection of features that seamlessly integrate into REAPER, the Digital Audio Workstation (DAW) software by Cockos, Inc
https://www.sws-extension.org/
MIT License
448 stars 85 forks source link

FR: Expose PCM_source::GetBitsPerSample() to ReaScript API #1010

Closed X-Raym closed 5 years ago

X-Raym commented 6 years ago

Hi,

there is currently no efficient way to get bit per sample of an audio file with ReaScript.

The function seems to exists in www.reaper.fm/files/reaper_plugin.h (but I don't know if it works). Looks for GetBitsPerSample().

It would be nice if we could expose it to ReaScript API, as handling such thing from ReaScript requires quite a lot of code. Here, it will be just one line.

Here was the discussion thread.

Thx !

cfillion commented 6 years ago

I also added APIs for getting/setting pcm sources online/offline status. The test build is at https://cfillion.ca/files/sws/pcm-source-api/.

X-Raym commented 6 years ago

@cfillion Excellent ! So more handy that the whole lua code I use to have (more than 100lines, with a shell comand etc for v1, then full file parsing for v2 in 20 lines... not just 1 !).

item = reaper.GetSelectedMediaItem( 0, 0 )
take = reaper.GetActiveTake( item )
source =  reaper.GetMediaItemTake_Source( take )
bit_depth = reaper.CF_GetMediaSourceBitDepth(source)

I tested with all bit depth avaible by wavefile, seems to work good, exept very esoteric one like 4 (IMA ADPCM) and Bits/sample: 2 (cADPCM) which returns simply 16, but I honestly don't know them maybe it is expected (also, it is not on SWS side to fix this). In Media Properties and BWFMetaEdit, they do appears like 4 and 2 bits files though. SO I guess it will be something to fix on cockos side. (and add a note in the doc meanwhile)

image (the 2 and 4 bits return 16 with the function)

Nice thing is that it do work for mp3 and flac ! I didn't test other formats.

cfillion commented 6 years ago

exept very esoteric one like 4 (IMA ADPCM) and Bits/sample: 2 (cADPCM) which returns simply 16

That's odd, considering REAPER correctly identifies those in the Source Properties window.