PSPTune is a simple guitar tuner coded in LUA:
http://rapidshare.de/files/4196896/PSPT ... K.rar.html
anyone have any idea why the wav files are playing back in poor quality? would it be better if I converted them to XM modules?
PSPTune 0.1
Moderators: Shine, Insert_witty_name
excellent , it should help my daughter a bit ;)
mirrored the file here --> http://psp-news.dcemu.co.uk/psptune.shtml
mirrored the file here --> http://psp-news.dcemu.co.uk/psptune.shtml
Re: PSPTune 0.1
You are playing multiple sounds at once, because everytime your controls function is called, another play command is started, until the button is released. There are 4 sound channels (I think), so you hear an overlay of 4 times your sound, started with some pause between. You should start a new sound only when the button state changes. Then it is possible to play chords as well with your program. Try this code:Dark Killer wrote: anyone have any idea why the wav files are playing back in poor quality? would it be better if I converted them to XM modules?
Code: Select all
oldPad = Controls.read()
function controls()
pad = Controls.read()
if pad ~= oldPad then
oldPad = pad
if pad:cross() then
lowe:play()
end
if pad:circle() then
astring:play()
end
if pad:triangle() then
dstring:play()
end
if pad:square() then
gstring:play()
end
if pad:l() then
bstring:play()
end
if pad:r() then
highe:play()
end
if pad:select() then
tabview()
end
end
end
I don't know anything about guitar tuning, but what about a clear sine, like from a tuning fork? The code below creates the notes for a guitar (change the baseFrequency, if necessary) and caches it as wave files on memory stick (this takes some 2 minutes on PSP for the first start, on the PC emulator on my PC 2 seconds, for every next start it reads it from memory stick).
Looks like Lua is a bit slow for synthesizing sounds, any ideas for a nice Lua interface or some good C library to include for a software synthesizer?
Looks like Lua is a bit slow for synthesizing sounds, any ideas for a nice Lua interface or some good C library to include for a software synthesizer?
Code: Select all
-- write a number as a 32 bit integer to a file
function write32(file, value)
value = math.floor(value)
file:write(string.char(math.mod(value, 256), math.mod(value / 256, 256), math.mod(value / 256 / 256, 256), math.mod(value / 256 / 256 / 256, 256)))
end
-- write a number as a 16 bit integer to a file
function write16(file, value)
value = math.floor(value)
if value < 0 then value = 65536 + value end
file:write(string.char(math.mod(value, 256), math.mod(value / 256, 256)))
end
-- write a samples array to as a wave file
function writeWave(filename, sampleRate, samples)
file = io.open(filename, "w")
file:write("RIFF") -- chunk id
len = table.getn(samples)
write32(file, 2 * len + 36) -- file size
file:write("WAVE") -- riff type
file:write("fmt ") -- format chunk id
write32(file, 16) -- chunk size
write16(file, 1) -- PCM/umcompressed
write16(file, 1) -- number of channels
write32(file, sampleRate) -- sample rate
write32(file, 2 * sampleRate) -- bytes per second
write16(file, 2) -- number of bytes per sample for all channels
write16(file, 16) -- number of bits per sample for one channel
file:write("data")
write32(file, 2 * len)
for i=1,len do write16(file, samples[i] * 32767) end
file:close()
end
-- create note table with frequency entry
function createNotes(octaveCount, base)
factor = math.pow(2, 1/12)
notes = {}
noteNames = { "c", "cs", "d", "ds", "e", "f", "fs", "g", "gs", "a", "as", "b" }
for octave = 1, octaveCount do
i = 0
for _, noteName in noteNames do
fullNoteName = noteName .. octave
notes[fullNoteName] = {}
notes[fullNoteName].freq = base * math.pow(factor, i)
i = i + 1
end
base = base * 2
end
return notes
end
baseFrequency = 440
notes = createNotes(3, baseFrequency)
-- create all guitar notes and cache on memory stick
sampleRate = 22050
pi = math.atan(1) * 4
guitarNotes = { "e1", "a1", "d2", "g2", "b2", "e3" }
for _, guitarNote in guitarNotes do
waveFilename = guitarNote .. ".wav"
file = io.open(waveFilename)
if file then
file:close()
else
samples = {}
step = 2 * pi * notes[guitarNote].freq / sampleRate
seconds = 3
for i = 0, sampleRate * seconds - 1 do
samples[i+1] = math.sin(step * i)
end
writeWave(waveFilename, sampleRate, samples)
end
notes[guitarNote].sound = Sound.load(waveFilename)
end
-- load guitar notes
lowe = notes.e1.sound
astring = notes.a1.sound
dstring = notes.d2.sound
gstring = notes.g2.sound
bstring = notes.b2.sound
highe = notes.e3.sound