1 files changed, 42 insertions(+), 0 deletions(-)

M player/channelmixer.go
M player/channelmixer.go +42 -0
@@ 26,6 26,8 @@ type ChannelMixer struct {
 	// when ready content should be set to
 	// channelRenderBufAcc ?
 	tempChannelRenderBufAcc [][][2]float64
+	// option ?
+	accumulateBuffers bool
 	
 	// test
 	outTestFile *os.File

          
@@ 45,6 47,9 @@ func NewChannelMixer(s *ChannelSys) *Cha
 		channelRenderBufAccLen: 200,
 		//channelRenderBufAccLen: 100,
 		
+		accumulateBuffers: true,
+		//accumulateBuffers: false,
+		
 		writeSeparateOutputChannels: true,
 		//writeSeparateOutputChannels: false,
 	}

          
@@ 225,9 230,46 @@ func (cm *ChannelMixer) RenderChannelTic
 		cm.renderTickBuf[chId] = buf
 	}
 	
+	// XXX ?
+	if cm.accumulateBuffers {
+		cm.writeToChannelAccBuffer(chId, buf)
+	}
+	
 	return buf
 }
 
+// explicit buf (?)
+func (cm *ChannelMixer) writeToChannelAccBuffer(chId int, buf [][2]float64) {
+//func (cm *ChannelMixer) writeToChannelAccBuffer(chId int) {
+	
+	tmpBuf := cm.tempChannelRenderBufAcc[chId]
+	dstBuf := cm.channelRenderBufAcc[chId]
+	xlen := cm.channelRenderBufAccLen
+	
+	// append to tmp buf
+	tmpBuf = append(tmpBuf, buf...)
+	
+	println("len tmpBuf:", len(tmpBuf))
+	println("len dstBuf:", len(dstBuf))
+	
+	// XXX update the target buffer (?)
+	if len(tmpBuf) > xlen {
+		println("do write...")
+		
+		// reset target buf ?
+		//dstBuf = dstBuf[:]
+		//dstBuf = append(dstBuf, tmpBuf[:xlen])
+		// copy data
+		dstBuf = tmpBuf[:xlen]
+		
+		println("x dstBuf:", dstBuf)
+		println("x len dstBuf:", len(dstBuf))
+		
+		// truncate tmp buf ?
+		tmpBuf = tmpBuf[xlen:]
+	}
+}
+
 // tickSize = tickSize samples
 func (cm *ChannelMixer) MixBufTest(tickSize int) [][2]float64 {
 	n := cm.channelSys.numChannels