TheLinx / lao

A library for audio output through Lua.
http://thelinx.github.com/lao/
18 stars 2 forks source link

not play sounds #11

Open ghost opened 3 years ago

ghost commented 3 years ago

i'm using the example ao_live.lua but show this error, my operating system is GNU/Linux:

$ luajit ao_live.lua

=================================================
=> type:    live
=> priority:    50
=> options:
     - server
     - sink
     - dev
     - id
     - verbose
     - quiet
     - matrix
     - debug
     - client_namebuffer_time
=> shortName:   pulse
=> preferredByteFormat: native
=> comment: Outputs to the PulseAudio Sound Server
=> name:    PulseAudio Output
=================================================
=> type:    live
=> priority:    20
=> options:
     - dsp
     - dev
     - id
     - buffer_time
     - verbose
     - quiet
     - matrix
     - debug
=> shortName:   oss
=> preferredByteFormat: native
=> comment: Outputs audio to the Open Sound System driver.
=> name:    OSS audio driver output 
=================================================
=> type:    live
=> priority:    0
=> options:
     - debug
     - verbose
     - matrix
     - quiet
=> shortName:   null
=> preferredByteFormat: native
=> comment: This driver does nothing.
=> name:    Null output
=================================================
=> type:    file
=> priority:    0
=> options:
     - matrix
     - verbose
     - quiet
     - debug
=> shortName:   wav
=> preferredByteFormat: little
=> comment: Sends output to a .wav file
=> name:    WAV file output
=================================================
=> type:    file
=> priority:    0
=> options:
     - byteorder
     - matrix
     - verbose
     - quiet
     - debug
=> shortName:   raw
=> preferredByteFormat: native
=> comment: Writes raw audio samples to a file
=> name:    RAW sample output
=================================================
=> type:    file
=> priority:    0
=> options:
     - matrix
     - verbose
     - quiet
     - debug
=> shortName:   au
=> preferredByteFormat: big
=> comment: Sends output to a .au file
=> name:    AU file output
=================================================
=> Device ID: 0
=================================================
luajit: ao_live.lua:32: cannot open the device
stack traceback:
    [C]: in function 'openLive'
    ao_live.lua:32: in main chunk
    [C]: at 0x5564d7c0cf40
ghost commented 3 years ago

I'm using this code:

local ao = require("ao")

-- ao.initialize()   is done automatically :-)
-- you will only need it if you have to restart the environment

-- Setup the default live driver
local default_driver = ao.defaultDriverId()
local format = { bits=16; channels=2; rate=44100; byteFormat="little"; }

local info = ao.driverInfoList()

for _,key in pairs(info) do
    print("=================================================")

    for option, value in pairs(key) do
        if option == "options" then
            print("=> "..option..":")
            for k, v in ipairs(value) do
                print("\t - "..v)
            end
        else
            print("=> "..option..":\t"..value)
        end
    end
end

print("=================================================")
print("=> Device ID: "..default_driver)
print("=================================================")

-- Open the driver
local device = ao.openLive(default_driver, format)
if not device then error("Error opening device.") end

-- Play a one second sine-wave
local freq = 440.0
local buf_size = format.bits/8 * format.channels * format.rate
local buffer = {}
for i = 0,format.rate do    -- one second
   sample = 0.75 * math.sin(2*math.pi*freq*i / format.rate)
   buffer[2*i+1] = sample   -- left
   buffer[2*i+2] = sample   -- right
end
device:play( ao.array2string(buffer) )   -- assumes 16 bits ...

-- Close and shutdown is handled by the garbage collector :-)