-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples for converting sample/bitrate? #1
Comments
I'm not sure if this is what you want, to be more precise, how would you do it from the command line with local libsox = require("libsox")
local sox = libsox:new()
local effect = nil
local sample_rate = 22050/2 -- New sample rate
local sound_input = '/tmp/coco.mp3' -- Input sound
local sound_output = '/tmp/coco2.mp3' -- Output sound
--All libSoX applications must start by initialising the SoX library
if not sox:init() then
error("Failed to initialize SoX")
end
--Open audiofile
local input = sox:open_read(sound_input)
if not input then
error("Failed to open input handler")
end
local in_signal = sox:signal(input)
--Open soundcard
--Change "alsa" in this line to use an alternative audio device driver:
local output = sox:open_write('default', {
rate=sample_rate,channels=2,precision=16
}, 'alsa')
--Write output file
--local output = sox:open_write(sound_output,{
--rate=sample_rate,channels=2,precision=16
--}, 'mp3')
if not output then
error("Failed to open output handler")
end
local out_signal = sox:signal(output)
--Create an effects chain; some effects need to know about the input
--or output file encoding so we provide that information here
local chain = sox:create_effects_chain(input, output)
local interm_signal = input -- NB: deep copy
effect = sox:create_effect(sox:find_effect("input"))
assert(sox:effect_options(effect, 1, input))
assert(sox:add_effect(chain, effect, input, input))
effect = nil
effect = sox:create_effect(sox:find_effect("rate"))
assert(sox:effect_options(effect, 1, sample_rate))
assert(sox:add_effect(chain, effect, interm_signal, input))
effect = nil
effect = sox:create_effect(sox:find_effect("output"))
assert(sox:effect_options(effect, 1, output))
assert(sox:add_effect(chain, effect, input, input))
effect = nil
--Flow samples through the effects processing chain until EOF is reached
sox:flow_effects(chain)
--All done; tidy up:
sox:delete_effects_chain(chain)
sox:close(input)
sox:close(output)
sox:quit()
|
Hey, thanks for your reply. If I follow along your example, I get incorrect results. I have built my function like this:
I call it like this:
The resulting files I get are wrong, as shown in their infos: Any ideas what is wrong here? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
I would really like to see an example of converting a file's bit depth and sample rate, I have been trying to get this to work but can not, would it be possible to see some simple Lua code to demonstrate?
The text was updated successfully, but these errors were encountered: