Pitch detection delays timers?

So I will have these notes spawning, and all is fine unless i hold a pitch that i sing. So if i hold the pitch, the notes literally will pause until i stop. Why is this, and how can i fix it!?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
local white = display.newRect(0, 0, 480, 320)
local back = display.newImage("newclef.png", 0, 0)
back:scale("1","1") 
_G.score = 0
hit = 0
txt = display.newText(score, 200, 10, system.DefaultFont, 25)
txt:setTextColor("193","42","221")
local r = media.newRecording()
r:startTuner()
r:startRecording()
 notesnum = 0
first = true
local line = display.newLine(150, 66, 150, 270)
line:setColor(255, 0, 0)
display.setStatusBar( display.HiddenStatusBar )
 
notes = {
{note="d", freq="146", top="293", more="587", posy="221", rot=false, sound="media/d.wav"},
{note="e", freq="164", top="329", more="659", posy="200", rot=false, sound ="media/e.wav"},
{note="f", freq="174", top="349", more="698", posy="175", rot=false, sound="media/f.wav"},
{note="g", freq="196", top="392", more="783", posy="153", rot=false, sound="media/g.wav"},
{note="a", freq="220", top="440", more="55", posy="124", rot=false, sound="media/a.wav"},
{note="b", freq="246", top="493", more="61", posy="230", rot=true, sound="media/b.wav"},
{note="c", freq="261", top="523", more="65", posy="211", rot=true, sound="media/c.wav"},
{note="d2", freq="293", top="587", more="146", posy="185", rot=true , sound="media/d.wav"},
{note="e2", freq="329", top="659", more="164", posy="159", rot=true , sound="media/e.wav"},
{note="f2", freq="349", top="698", more="174",posy="130", rot=true, sound="media/f.wav"},
{note="g2", freq="392", top="783", more="196",posy="110", rot=true, sound="media/g.wav"}
}
 
-------------------------
dec = "3"
 
i = notes[1]
 
 
 
-------------------------
function note(index)
notesnum = notesnum + 1
local note = display.newImage("newnote.png")
localGroup:insert(note)
 
function noteDelete()
note:removeSelf()
notesnum = notesnum - 1
end
if notes[index].rot == true then
note:rotate("180")
end
note.x="500"
note.y= notes[index].posy
 
freq1 = notes[index].freq
top1 = notes[index].top
more1 = notes[index].more
 
function check(event)
f = r:getTunerFrequency()
if f < freq1 + 20 and f > freq1 - 20 or f < top1 + 20 and f > top1 - 20 or f < more1 + 10 and f > more1 - 10 then
 
x = nil
hit = 0
noteDelete()
_G.score = _G.score + 1
txt.text = score
end
return true
end
Runtime:addEventListener("enterFrame", check)
 
local function move()
if note then
note.x = note.x - 4.5
if note.x < 140 then
 
timer.cancel(time1)
note:removeSelf()
timer.cancel(time)
director:changeScene("over", "moveFromBottom")
end
end
end
 
time1 = timer.performWithDelay(20, move, -1)
 
return note
end
 
 
 
 
 
local noteTable = {}
 
newNote = function(e)
 
noteTable[#notes + 1]  = note(e)
end
 
 
local function newnot()
nex = math.random(1,11)
 
if first == true then
local note_sound = audio.loadSound( notes[nex].sound)
audio.play(note_sound);
end
 
if last then
if nex == last and nex ~= 11  then
nex = nex + 1
end
end
 
local function resume()
 
timer.resume( time )
newNote(nex)
print("resuming")
end
 
if first == true then
 
timer.pause( time )
print("paused")
timer.performWithDelay("2000", resume)
first = false
else 
newNote(nex)
end
 
 
last = nex
end
time = timer.performWithDelay(3000, newnot, -1)

I didn't fully understand the question, but are you on iOS? For performance reasons, audio recording shuts off audio playback. If you need simultaneous recording and playback, you need to use the (advanced) Audio Session APIs to change the mixing mode to audio.PlayAndRecordMixMode.

http://developer.anscamobile.com/forum/2011/06/05/new-audiosession-properties

Thanks, but i'm not using audio playback except once, before the recording even matters. The playback and recording is working fine. The problem is that when I constantly hold down a note, the other notes stop. For example, it is as if playing the correct pitch deletes the note and stops to notes.

Does this make since? So whenever I hold down a note, as long as it is the correct (variable f) above, all of the notes appear to stop moving.

Is there a logic bug? If the note doesn't change, then you don't get a 'newnot' and you never play anything. The sound you are playing will eventually come to an end (you are not looping the sample) so eventually nothing will be playing until the note changes.

Also, be careful about how you use loadSound. It was meant to be called to preload your samples (say at launch time) into memory because loading may not be instantaneous. And generally speaking, we are discouraging you from calling loadSound on the same file that is already loaded.

views:2122 update:2012/2/8 8:46:10
corona forums © 2003-2011