forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PSPTune 0.1

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Dark Killer



Joined: 25 Jan 2005
Posts: 32

PostPosted: Sun Aug 21, 2005 9:53 am    Post subject: PSPTune 0.1 Reply with quote

PSPTune is a simple guitar tuner coded in LUA:

http://rapidshare.de/files/4196896/PSPTune_0.1-DK.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?
Back to top
View user's profile Send private message AIM Address
emumaniac



Joined: 08 May 2005
Posts: 79

PostPosted: Sun Aug 21, 2005 5:50 pm    Post subject: Reply with quote

excellent , it should help my daughter a bit ;)

mirrored the file here --> http://psp-news.dcemu.co.uk/psptune.shtml
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Mon Aug 22, 2005 12:54 am    Post subject: Re: PSPTune 0.1 Reply with quote

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?


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:

Code:

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


Some more improvements: the native sampling rate of the PSP is 22050 Hz, so it doesn't make sense to save it in higher sample rates, because it will be scaled down with quality loss on the PSP. And you should set your recordings to maximum gain, the peak level of your wav files are below -10 dB (with 0 dB = maximum digital amplitude).
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Mon Aug 22, 2005 4:33 am    Post subject: Reply with quote

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?

Code:

-- 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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group