From 7ae9d4bada9e5aa9eb9983f4dd35fd181967d837 Mon Sep 17 00:00:00 2001 From: tudnai Date: Sat, 12 Mar 2022 08:04:23 -0800 Subject: [PATCH] Much better sound + improvements + started debugger project --- A2Mac.xcodeproj/project.pbxproj | 12 + .../xcdebugger/Expressions.xcexplist | 183 +++++---- A2Mac/A2Mac-Bridging-Header.h | 1 + A2Mac/Base.lproj/Main.storyboard | 44 +- A2Mac/Debugger.swift | 9 + A2Mac/Shaders.metal | 38 +- A2Mac/ViewController.swift | 164 ++++++-- convert_spkr_buf_to_wav.py | 51 +++ src/cpu/6502.h | 2 +- src/dev/audio/speaker.c | 380 +++++++----------- 10 files changed, 524 insertions(+), 360 deletions(-) create mode 100644 A2Mac/Debugger.swift create mode 100755 convert_spkr_buf_to_wav.py diff --git a/A2Mac.xcodeproj/project.pbxproj b/A2Mac.xcodeproj/project.pbxproj index 9298711..16498d1 100644 --- a/A2Mac.xcodeproj/project.pbxproj +++ b/A2Mac.xcodeproj/project.pbxproj @@ -191,6 +191,10 @@ 32C4532E233345430000EBA1 /* MonitorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* MonitorView.swift */; }; 32C4532F233345820000EBA1 /* MonitorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* MonitorView.swift */; }; 32C45330233345820000EBA1 /* MonitorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* MonitorView.swift */; }; + 32C6995227C5439300D0F25D /* Debugger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C6995127C5439300D0F25D /* Debugger.swift */; }; + 32C6995327C5439300D0F25D /* Debugger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C6995127C5439300D0F25D /* Debugger.swift */; }; + 32C6995D27C548C800D0F25D /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 32B18435233F10BC00DBB4AB /* Shaders.metal */; }; + 32C6996727C548C900D0F25D /* Shaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = 32B18435233F10BC00DBB4AB /* Shaders.metal */; }; 32E3126624A7193700E61891 /* disk_ii_arm.sfx in Resources */ = {isa = PBXBuildFile; fileRef = 32E3126424A7193700E61891 /* disk_ii_arm.sfx */; }; 32E3126724A7194900E61891 /* disk_ii_arm.sfx in Copy SFX Files */ = {isa = PBXBuildFile; fileRef = 32E3126424A7193700E61891 /* disk_ii_arm.sfx */; }; 32E3126924A98B9300E61891 /* dsk2woz.c in Sources */ = {isa = PBXBuildFile; fileRef = 32E3126824A98B9300E61891 /* dsk2woz.c */; }; @@ -628,6 +632,7 @@ 326426112328ADF4008B615F /* Apple_II_ROM.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = Apple_II_ROM.s; sourceTree = ""; }; 3267641524B6572E000BEA11 /* Merlin Assembler.woz */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Merlin Assembler.woz"; sourceTree = ""; }; 3267641724BCC9A5000BEA11 /* COPYING */ = {isa = PBXFileReference; lastKnownFileType = text; path = COPYING; sourceTree = ""; }; + 3268B96F27DBD219003FBDCC /* convert_spkr_buf_to_wav.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = convert_spkr_buf_to_wav.py; sourceTree = SOURCE_ROOT; }; 3268E68E2474E24900047474 /* paddle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = paddle.h; sourceTree = ""; }; 326B56E424AD8E89009BA0AC /* gobackward.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = gobackward.png; sourceTree = ""; }; 326B56E624AD906D009BA0AC /* doc.text.viewfinder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = doc.text.viewfinder.png; sourceTree = ""; }; @@ -686,6 +691,7 @@ 32C4532B2331FED90000EBA1 /* Functiontest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Functiontest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32C4532C2331FEDA0000EBA1 /* A2Mac copy2-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "A2Mac copy2-Info.plist"; path = "/Users/trudnai/Projects/A2Mac/A2Mac copy2-Info.plist"; sourceTree = ""; }; 32C4532D233345420000EBA1 /* MonitorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonitorView.swift; sourceTree = ""; }; + 32C6995127C5439300D0F25D /* Debugger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Debugger.swift; sourceTree = ""; }; 32DBF7632334657900DD50E7 /* HiRes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HiRes.swift; sourceTree = ""; }; 32DBF76723373FB400DD50E7 /* disassembler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = disassembler.h; sourceTree = ""; }; 32E21BE62491BF8B006C0C72 /* apple-rainbow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "apple-rainbow.png"; sourceTree = ""; }; @@ -1101,10 +1107,12 @@ 32B18438233FAB3900DBB4AB /* verticies.swift */, 32BFFB5A22EACC630003B53F /* AppDelegate.swift */, 32BFFB5C22EACC630003B53F /* ViewController.swift */, + 32C6995127C5439300D0F25D /* Debugger.swift */, 323D042F24898AB70086A901 /* PreferencesViewController.swift */, 323D04312489BFD80086A901 /* PreferencesWindowController.swift */, 32B18435233F10BC00DBB4AB /* Shaders.metal */, 32C4532D233345420000EBA1 /* MonitorView.swift */, + 3268B96F27DBD219003FBDCC /* convert_spkr_buf_to_wav.py */, 32544194264A6C1600B7E3ED /* DisplayView.swift */, 32C453072331C0910000EBA1 /* NSLayoutManager-Extension.swift */, 32440BA22480D5C0000F9DA1 /* LoRes.swift */, @@ -1560,6 +1568,7 @@ 32799F7E264B1A5700255669 /* PreferencesWindowController.swift in Sources */, 32799F80264B1A5700255669 /* dsk2woz.c in Sources */, 32799F81264B1A5700255669 /* disk.c in Sources */, + 32C6996727C548C900D0F25D /* Shaders.metal in Sources */, 32799F82264B1A5700255669 /* woz.c in Sources */, 32A6AB10266AF5160023257A /* paddle.c in Sources */, 32799F83264B1A5700255669 /* speaker.c in Sources */, @@ -1567,6 +1576,7 @@ 32799F85264B1A5700255669 /* ViewController.swift in Sources */, 32799F86264B1A5700255669 /* HiRes.swift in Sources */, 32799F87264B1A5700255669 /* LoRes.swift in Sources */, + 32C6995327C5439300D0F25D /* Debugger.swift in Sources */, 32799F88264B1A5700255669 /* RepeatingTimer.swift in Sources */, 32A6AAFA266AEDF50023257A /* mmio.c in Sources */, 32799F8A264B1A5700255669 /* MonitorView.swift in Sources */, @@ -1587,6 +1597,7 @@ 323D04332489BFD80086A901 /* PreferencesWindowController.swift in Sources */, 32E3126924A98B9300E61891 /* dsk2woz.c in Sources */, 325EB63623F8F78300C6B4A4 /* disk.c in Sources */, + 32C6995D27C548C800D0F25D /* Shaders.metal in Sources */, 325EB62F23F8856F00C6B4A4 /* woz.c in Sources */, 32A6AB0F266AF5160023257A /* paddle.c in Sources */, 32A9F74A2467B60B004902A1 /* speaker.c in Sources */, @@ -1594,6 +1605,7 @@ 32BFFB5D22EACC630003B53F /* ViewController.swift in Sources */, 325EB69323FE6C6200C6B4A4 /* HiRes.swift in Sources */, 32440BA32480D5C0000F9DA1 /* LoRes.swift in Sources */, + 32C6995227C5439300D0F25D /* Debugger.swift in Sources */, 32C45306232E3EEF0000EBA1 /* RepeatingTimer.swift in Sources */, 32A6AAF0266AEDF40023257A /* mmio.c in Sources */, 32C4532E233345430000EBA1 /* MonitorView.swift in Sources */, diff --git a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist index e9d4cc3..82d931f 100644 --- a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -22,13 +22,10 @@ + contextName = "ViewController.extraBuf(_:):ViewController.swift"> - - + value = "soundGapLabel"> @@ -89,7 +86,7 @@ contextName = "closure #1 in ViewController.Update():ViewController.swift"> + value = "txtArr"> @@ -101,7 +98,7 @@ value = "MEMcfg.txt_page_2"> + value = "MEMcfg.is_80STORE"> @@ -176,6 +173,14 @@ + + + + + + @@ -319,51 +324,36 @@ + contextName = "spkr_toggle_ema:speaker.c"> + value = "spkr_samples[i]"> + value = "level / (spkr_sample_idx - from_idx)"> + value = "spkr_sample_idx - from_idx"> + value = "spkr_samples[ spkr_sample_idx ]"> - - - - - - - - - - - - - - - - + value = "level / ((int)spkr_sample_idx - from_idx + 1)"> + + + + + + @@ -396,10 +386,51 @@ contextName = "set_flags_NZ:common.h"> + contextName = "MonitorView.frameDidChange(notification:):MonitorView.swift"> + value = "frame.size"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -413,7 +444,7 @@ value = "pdl_value[pdl]"> + value = "normalized_time >= pdl_value[pdl] ? 255 : 0"> @@ -425,7 +456,7 @@ value = "1 * 512 * (1 - ( 3300 / 3300.0 ))"> + value = "normalized_time"> @@ -435,6 +466,9 @@ + + @@ -473,7 +507,7 @@ contextName = "LoRes.Update():LoRes.swift"> + value = "blockChanged[ screenIdx ]"> @@ -482,7 +516,7 @@ value = "UInt8(block & 4)"> + value = "UInt8( (block >> 4) & 0x0F )"> @@ -517,10 +551,10 @@ contextName = "set_flags_NZC:common.h"> + value = "(unsigned)test "> + value = "(unsigned)0xFF"> @@ -670,11 +704,14 @@ contextName = "spkr_toggle:speaker.c"> + value = "( (spkr_clk + m6502.clkfrm) / ( default_MHz_6502 * 1000 * 1000 / spkr_sample_rate)) * 2"> + + @@ -685,10 +722,7 @@ value = "( (spkr_clk + m6502.clkfrm) / ( 1024000 / spkr_sample_rate ) ) * 2"> - - + value = "spkr_samples[spkr_sample_last_idx]"> @@ -696,17 +730,14 @@ contextName = "HiRes.draw(_:):HiRes.swift"> + value = "linAddr"> + value = "shadowScreen"> - - @@ -717,19 +748,22 @@ value = "HiResLineAddrTbl"> + value = "ctx?.bitmapInfo"> + value = "(blockH7 | ( block & bitMask ))"> + + + value = "ctx?.bitsPerComponent"> + value = "ctx?.data"> @@ -745,13 +779,13 @@ contextName = "HiRes.compute():HiRes.swift"> + value = "computePipelineState.maxTotalThreadsPerThreadgroup"> + value = "UnsafeRawBufferPointer(result)"> @@ -803,13 +837,13 @@ value = "Apple2_64K_RAM + 0x3600"> + value = "m6502.PC"> + value = "Apple2_64K_AUX + 0x3600"> @@ -865,7 +899,7 @@ value = "new"> + value = "WOZwrite.shift16"> @@ -877,7 +911,7 @@ value = "(1 << i) - 1"> + value = "WOZtmp.shift16"> @@ -924,7 +958,10 @@ value = "textDisplay_height_diff"> + value = "textDisplay.frame"> + + @@ -933,10 +970,7 @@ value = "frame.size"> - - + value = "textDisplay_width_diff"> @@ -947,10 +981,10 @@ value = "Apple2_64K_AUX + 0xC600"> + value = "(void*)rom"> + value = "Apple2_64K_RAM + 0xC600"> @@ -1003,10 +1037,13 @@ + contextName = "BRA:6502_instr_branch.h"> + value = ""> + + diff --git a/A2Mac/A2Mac-Bridging-Header.h b/A2Mac/A2Mac-Bridging-Header.h index 2df058b..05a49f4 100644 --- a/A2Mac/A2Mac-Bridging-Header.h +++ b/A2Mac/A2Mac-Bridging-Header.h @@ -34,6 +34,7 @@ #import "dsk2woz.h" #import "mmio.h" #import "hires.h" +#import "woz.h" #endif /* A2Mac_Bridging_Header_h */ diff --git a/A2Mac/Base.lproj/Main.storyboard b/A2Mac/Base.lproj/Main.storyboard index eca23dc..e3394a4 100644 --- a/A2Mac/Base.lproj/Main.storyboard +++ b/A2Mac/Base.lproj/Main.storyboard @@ -1929,10 +1929,10 @@ - + - + + + + + + + + + + + + + + + + @@ -2014,7 +2029,7 @@ - + @@ -2049,6 +2064,8 @@ + + @@ -2065,6 +2082,8 @@ + + @@ -2141,6 +2160,7 @@ + diff --git a/A2Mac/Debugger.swift b/A2Mac/Debugger.swift new file mode 100644 index 0000000..ab15365 --- /dev/null +++ b/A2Mac/Debugger.swift @@ -0,0 +1,9 @@ +// +// Debugger.swift +// A2Mac +// +// Created by Tamas Rudnai on 2/22/22. +// Copyright © 2022 GameAlloy. All rights reserved. +// + +import Foundation diff --git a/A2Mac/Shaders.metal b/A2Mac/Shaders.metal index a9a9a62..47cca62 100644 --- a/A2Mac/Shaders.metal +++ b/A2Mac/Shaders.metal @@ -25,14 +25,35 @@ using namespace metal; -vertex float4 basic_vertex( // 1 +// triangles +vertex float4 basic_vertex( // 1 const device packed_float3* vertex_array [[ buffer(0) ]], // 2 - unsigned int vid [[ vertex_id ]]) { // 3 - return float4(vertex_array[vid], 1.0); // 4 + unsigned int vid [[ vertex_id ]] // 3 +){ + return float4(vertex_array[vid], 1.0); // 4 } +//struct Vertex { +// float4 position; +// float4 color; +//}; +// +//struct VertexOut { +// float4 position [[position]]; +// float4 color; +//}; +// +//vertex VertexOut myVertexOut ( +// const Vertex* vertexArray [[ buffer(0) ]], +// unsigned int vid [[ vertex_id ]] +//){ +// VSO +//} + + +// color of triangles fragment half4 basic_fragment() { // 1 - return half4(0.7); // 2 + return half4( 255.0/255.0, 127.0/255.0, 255.0/255.0, 1.0); // half4(1.0); // 2 } @@ -46,4 +67,13 @@ kernel void add_arrays(device const float* inA, result[index] = inA[index] + inB[index] + 1; } +//vertex float4 basic_vertex( // 1 +// const device packed_float3* vertex_array [[ buffer(0) ]], // 2 +// unsigned int vid [[ vertex_id ]]) { // 3 +// return float4(vertex_array[vid], 1.0); // 4 +//} +// +//fragment half4 basic_fragment() { // 1 +// return half4(1.0); // 2 +//} diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index 503abd9..ead7f4d 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -25,6 +25,16 @@ import Cocoa import AVFoundation +//import Metal +// +//var device : MTLDevice! +//var metalLayer: CAMetalLayer! +//var vertexBuffer: MTLBuffer! +//var pipelineState: MTLRenderPipelineState! +//var commandQueue: MTLCommandQueue! +////var timer: CADisplayLink! + + let K : Double = 1000.0 let M : Double = (K * K) @@ -867,6 +877,8 @@ class ViewController: NSViewController { } // } + +// render() } @@ -1000,9 +1012,85 @@ class ViewController: NSViewController { ViewController.current = self } + +// func render() { +// +// var x = vertexData[2 * 3 + 0] +// x -= 0.01 +// if x < -1 { +// x = 1 +// } +// vertexData[2 * 3 + 0] = x +// +// guard let drawable = metalLayer?.nextDrawable() else { return } +// let renderPassDescriptor = MTLRenderPassDescriptor() +// renderPassDescriptor.colorAttachments[0].texture = drawable.texture +// renderPassDescriptor.colorAttachments[0].loadAction = .clear +// renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor( +// red: 0.0, +// green: 104.0/255.0, +// blue: 55.0/255.0, +// alpha: 0.3) +// +// if let commandBuffer = commandQueue.makeCommandBuffer() { +// if let renderEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor) { +// renderEncoder.setRenderPipelineState(pipelineState) +// let dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0]) // 1 +// vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize, options: []) // 2 +// renderEncoder.setVertexBuffer(vertexBuffer, offset: 0, index: 0) +// renderEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1) +// renderEncoder.endEncoding() +// commandBuffer.present(drawable) +// commandBuffer.commit() +// } +// } +// } +// +// +// var vertexData: [Float] = [ +// 0.0, 1.0, 0.0, +// -1.0, -1.0, 0.0, +// 1.0, -1.0, 0.0 +// ] + override func viewDidLoad() { super.viewDidLoad() +// let layer = CALayer() +// hires.layer = layer +// hires.wantsLayer = true + +// device = MTLCreateSystemDefaultDevice() +// metalLayer = CAMetalLayer() // 1 +// metalLayer.device = device // 2 +// metalLayer.pixelFormat = .bgra8Unorm // 3 +// metalLayer.framebufferOnly = true // 4 +// metalLayer.frame = hires.layer!.frame // 5 +// hires.layer!.addSublayer(metalLayer) // 6 +// +// let dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0]) // 1 +// vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize, options: []) // 2 +// +// // 1 +// let defaultLibrary = device.makeDefaultLibrary()! +// let fragmentProgram = defaultLibrary.makeFunction(name: "basic_fragment") +// let vertexProgram = defaultLibrary.makeFunction(name: "basic_vertex") +// +// // 2 +// let pipelineStateDescriptor = MTLRenderPipelineDescriptor() +// pipelineStateDescriptor.vertexFunction = vertexProgram +// pipelineStateDescriptor.fragmentFunction = fragmentProgram +// pipelineStateDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm +// +// // 3 +// pipelineState = try! device.makeRenderPipelineState(descriptor: pipelineStateDescriptor) +// +// commandQueue = device.makeCommandQueue() + +// timer = CADisplayLink(target: self, selector: #selector(gameloop)) +// timer.add(to: RunLoop.main, forMode: .default) + + openLog() hires.clearScreen(); @@ -1108,40 +1196,40 @@ class ViewController: NSViewController { // spkr_extra_buf = Int32( 780 / fps ) spkr_extra_buf = 0 // 26 - switch freq { - case 0.25: - spkr_extra_buf = -65 - break - - case 0.5: - spkr_extra_buf = -140 - break - - case 1.5: - spkr_extra_buf = 175 - break - - case 2.0: -// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 2.961538461538462 ) // normally it should come up as 77, but this way it is calculated with FPS -// spkr_extra_buf = 20 - spkr_extra_buf = 195 // 88 - break - - case 2.8: - spkr_extra_buf = 65 // 185 - break - - case 4.0: -// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 1.346153846153846 ) // normally it should come up as 35, but this way it is calculated with FPS -// spkr_extra_buf = 45 - spkr_extra_buf = 25 // 90 // 80 // 20 - break - - default: -// spkr_extra_buf = Int32( 780 / fps ) // normally it should come up as 26, but this way it is calculated with FPS - spkr_extra_buf = 0 // 26 - break - } +// switch freq { +// case 0.25: +// spkr_extra_buf = -65 +// break +// +// case 0.5: +// spkr_extra_buf = -140 +// break +// +// case 1.5: +// spkr_extra_buf = 175 +// break +// +// case 2.0: +//// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 2.961538461538462 ) // normally it should come up as 77, but this way it is calculated with FPS +//// spkr_extra_buf = 20 +// spkr_extra_buf = 195 // 88 +// break +// +// case 2.8: +// spkr_extra_buf = 65 // 185 +// break +// +// case 4.0: +//// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 1.346153846153846 ) // normally it should come up as 35, but this way it is calculated with FPS +//// spkr_extra_buf = 45 +// spkr_extra_buf = 25 // 90 // 80 // 20 +// break +// +// default: +//// spkr_extra_buf = Int32( 780 / fps ) // normally it should come up as 26, but this way it is calculated with FPS +// spkr_extra_buf = 0 // 26 +// break +// } soundGapLabel.title = String( spkr_extra_buf ) soundGapSlider.integerValue = Int(spkr_extra_buf) @@ -1178,6 +1266,14 @@ class ViewController: NSViewController { trailingEdgeLabel.title = "TE: " + String( SPKR_FADE_TRAILING_EDGE ) } + + @IBOutlet weak var wozExtraLabel: NSTextFieldCell! + @IBAction func wozExtraSelected(_ sender: NSSlider) { + extraForward = Int32(sender.floatValue) + wozExtraLabel.title = "WE: " + String( extraForward ) + } + + func setSimulationMode( mode : String ) { switch ( mode ) { case "Eco": diff --git a/convert_spkr_buf_to_wav.py b/convert_spkr_buf_to_wav.py new file mode 100755 index 0000000..847f257 --- /dev/null +++ b/convert_spkr_buf_to_wav.py @@ -0,0 +1,51 @@ +#!/usr/local/bin/python3 + +### Convert SPKR Buffer to WAV -- (c) by Tamas Rudnai 2022 +### +### This utility convert SPKR buffer output to an uncompressed WAV file +### +### Purpose is that sound generation can be analyzed by audio editor - Audacity for example +### + +import os +import struct + +binpath = '/Users/trudnai/Library/Containers/com.trudnai.steveii/Data/' +binfilename = binpath + 'steve2_audio_debug.bin' +data_size = os.path.getsize(binfilename) +channels = 2 +sample_rate = 192000 # must be the same as in speaker.c : spkr_sample_rate +bits_per_sample = 16 +header_size = 44 + +with open( binfilename, 'rb') as binfile: + with open( 'steve2_audio_debug.wav', 'wb+') as wavfile: + # WAV HEADER + wavfile.write( 'RIFF'.encode() ) # Marks the file as a riff file. Characters are each 1 byte long + wavfile.write( struct.pack('I', data_size + header_size ) ) # Size of the overall file - 8 bytes, in bytes (32-bit integer). Typically you’d fill this in after creation + wavfile.write( 'WAVE'.encode() ) # File Type Header. For our purposes, it always equals “WAVE” + + # FMT HEADER + wavfile.write( 'fmt '.encode() ) # Format chunk marker. Includes trailing null (tr: Space works, null don't) + wavfile.write( struct.pack('I', 16 ) ) # Length of format data as listed above + + # FMT DATA + wavfile.write( struct.pack('H', 1 ) ) # Type of format (1 is PCM) - 2 byte integer + wavfile.write( struct.pack('H', channels ) ) # Number of Channels - 2 byte integer + wavfile.write( struct.pack('I', sample_rate ) ) # Sample Rate - 32 byte integer. Common values are 44100 (CD), 48000 (DAT). Sample Rate = Number of Samples per second, or Hertz + wavfile.write( struct.pack('I', int(sample_rate * bits_per_sample * channels / 8) ) ) # (Sample Rate * BitsPerSample * Channels) / 8 + wavfile.write( struct.pack('H', 4 ) ) # 0: (BitsPerSample * Channels) / 8 + # 1: 8 bit mono2 + # 2: 8 bit stereo + # 3: 16 bit mono + # 4: 16 bit stereo + wavfile.write( struct.pack('H', bits_per_sample ) ) # Bits per sample + + # DATA HEADER + wavfile.write( 'data'.encode() ) # “data” chunk header. Marks the beginning of the data section + wavfile.write( struct.pack('I', data_size ) ) # Size of the data section + + # // WAV DATA + wavfile.write( binfile.read() ) + + diff --git a/src/cpu/6502.h b/src/cpu/6502.h index 52e2d0b..5fe0fe3 100644 --- a/src/cpu/6502.h +++ b/src/cpu/6502.h @@ -198,7 +198,7 @@ extern double mhz; #define DEF_VIDEO_DIV 1U #define DEF_SPKR_DIV 1U -#define GAME_FPS 480U // 480U +#define GAME_FPS 180U // 480U #define GAME_VIDEO_DIV (GAME_FPS / 60U) extern unsigned int video_fps_divider; diff --git a/src/dev/audio/speaker.c b/src/dev/audio/speaker.c index 447ab32..31e619a 100644 --- a/src/dev/audio/speaker.c +++ b/src/dev/audio/speaker.c @@ -70,9 +70,6 @@ ALCcontext *ctx = NULL; int spkr_att = 0; int spkr_level = SPKR_LEVEL_ZERO; int spkr_level_ema = SPKR_LEVEL_ZERO; -int spkr_level_dema = SPKR_LEVEL_ZERO; -int spkr_level_tema = SPKR_LEVEL_ZERO; -int spkr_level_qema = SPKR_LEVEL_ZERO; int spkr_last_level = SPKR_LEVEL_ZERO; #define BUFFER_COUNT 256 @@ -173,17 +170,41 @@ void spkr_load_sfx( const char * bundlePath ) { diskioerr_sfx_len = load_sfx(bundlePath, "disk_ii_io_error.sfx", &diskioerr_sfx); } +#define NO_SPKR_KEEP_PITCH + +#define NO_SPKR_DEBUG +#ifdef SPKR_DEBUG +static const char * spkr_debug_filename = "steve2_audio_debug.bin"; +FILE * spkr_debug_file = NULL; +#endif + + +void spkr_fade(float fadeLevel, unsigned idx) { + // Fade + while ( ( fadeLevel < -1 ) || ( fadeLevel > 1 ) ) { + spkr_samples[ idx++ ] = SPKR_LEVEL_ZERO + fadeLevel; + spkr_samples[ idx++ ] = SPKR_LEVEL_ZERO + fadeLevel; // stereo + + // how smooth we want the speeker to decay, so we will hear no pops and crackles + fadeLevel *= 0.999; + } + + // Fill with Zero to avoid pops + memset(spkr_samples + idx * sizeof(spkr_sample_t), 0, spkr_buf_size * sizeof(spkr_sample_t) * SPKR_CHANNELS); +} -FILE * af = NULL; // initialize OpenAL void spkr_init() { const char *defname = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); printf( "Default device: %s\n", defname ); -// // DEBUG ONLY!!! -// af = fopen("steve2_audio_debug.bin", "w+"); + // DEBUG ONLY!!! +#ifdef SPKR_DEBUG + spkr_debug_file = fopen(spkr_debug_filename, "w+"); +#endif + // restart OpenAL when restarting the virtual machine spkr_exit(); @@ -194,40 +215,16 @@ void spkr_init() { // Fill buffer with zeros memset( spkr_samples, 0, spkr_buf_alloc_size + spkr_extra_buf * sizeof(spkr_sample_t)); - float fadeLevel = SPKR_LEVEL_MAX; - - spkr_sample_idx = spkr_buf_size * (BUFFER_COUNT - 2); - - while ( ( fadeLevel < -1 ) || ( fadeLevel > 1 ) ) { - spkr_samples[ spkr_sample_idx++ ] = SPKR_LEVEL_ZERO + fadeLevel; - spkr_samples[ spkr_sample_idx++ ] = SPKR_LEVEL_ZERO + fadeLevel; // stereo - - // how smooth we want the speeker to decay, so we will hear no pops and crackles - fadeLevel *= 0.999; - } - - fadeLevel = SPKR_LEVEL_MIN; - - spkr_sample_idx = spkr_buf_size * (BUFFER_COUNT - 1); - - while ( ( fadeLevel < -1 ) || ( fadeLevel > 1 ) ) { - spkr_samples[ spkr_sample_idx++ ] = SPKR_LEVEL_ZERO + fadeLevel; - spkr_samples[ spkr_sample_idx++ ] = SPKR_LEVEL_ZERO + fadeLevel; // stereo - - // how smooth we want the speeker to decay, so we will hear no pops and crackles - fadeLevel *= 0.999; - } - - //spkr_samples[sample_idx] = spkr_level; - // memset(spkr_samples + spkr_sample_idx, 0, spkr_extra_buf * sizeof(spkr_sample_t)); - memset(spkr_samples + spkr_sample_idx, 0, (sample_buf_array_len - spkr_sample_idx) * sizeof(spkr_sample_t)); +// memset(spkr_samples + spkr_sample_idx * sizeof(spkr_sample_t), 0, (sample_buf_array_len - spkr_sample_idx) * sizeof(spkr_sample_t)); freeBuffers--; -// // DEBUG ONLY!!! -// fwrite(spkr_samples, sizeof(spkr_sample_t), spkr_sample_idx, af); -// fflush(af); - + // DEBUG ONLY!!! +#ifdef SPKR_DEBUG + fwrite(spkr_samples, sizeof(spkr_sample_t), spkr_sample_idx, spkr_debug_file); + fflush(spkr_debug_file); +#endif + alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, spkr_sample_idx * sizeof(spkr_sample_t), spkr_sample_rate); al_check_error(); alSourceQueueBuffers(spkr_src[SPKR_SRC_GAME_SFX], 1, &spkr_buffers[freeBuffers]); @@ -418,86 +415,18 @@ INLINE int ema( int val, int prev, float ema_len ) { } -void spkr_toggle_edge ( int level_max, const float initial_edge, const float fade_edge, const unsigned idx_diff ) { - -// float dumping = spkr_level - level_max; -// dumping *= initial_edge; - -// float ema_len = 21; - int ema_len = 7; // 8; - int ema_len_smooth = 8; - unsigned threshold = SPKR_SAMPLE_PWM_THRESHOLD; - unsigned limiter = 150; - - switch ((int)(MHz_6502 * 10)) { - case 02: - case 05: - ema_len = 8; - ema_len_smooth = 8; - threshold = SPKR_SAMPLE_PWM_THRESHOLD * 2; - limiter = 10; - break; - - case 15: - ema_len = 5; - ema_len_smooth = 7; - threshold = SPKR_SAMPLE_PWM_THRESHOLD / 1.5; - limiter = 128; - break; - - case 20: - case 28: - ema_len = 4; - ema_len_smooth = 6; - threshold = SPKR_SAMPLE_PWM_THRESHOLD / 2; - limiter = 128; - break; - - case 40: - ema_len = 3; - ema_len_smooth = 5; - threshold = SPKR_SAMPLE_PWM_THRESHOLD / 4; - limiter = 1024; - break; - - default: - break; +void spkr_toggle_square ( int level_max, const unsigned idx_diff ) { + // finish the aquare wave + while ( spkr_sample_last_idx < spkr_sample_idx ) { + spkr_samples[ spkr_sample_last_idx++ ] = spkr_level; + spkr_samples[ spkr_sample_last_idx++ ] = spkr_level; // stereo } - // save last index before we advance it... - spkr_sample_last_idx = spkr_sample_idx; + // start a new speaker level -- it might not be necessary, but... + spkr_samples[ spkr_sample_idx++ ] = level_max; + spkr_samples[ spkr_sample_idx++ ] = level_max; // stereo - spkr_level = spkr_samples[ spkr_sample_idx ]; - spkr_level_ema = spkr_level; - spkr_level_dema = spkr_level; - spkr_level_tema = spkr_level; - spkr_level_qema = spkr_level; - - if ( idx_diff < threshold ) { - ema_len = ema_len_smooth; - - if ( --spkr_att < 0 ) { - level_max = SPKR_LEVEL_ZERO; - } - } - else { - spkr_att = 1024; - } - - - for ( int i = 0; (i < spkr_buf_size * 2) && (abs(spkr_level - level_max) > limiter); i++ ) { - spkr_level_ema = ema(level_max, spkr_level_ema, ema_len); - spkr_level_dema = ema(spkr_level_ema, spkr_level_dema, ema_len); - spkr_level_tema = ema(spkr_level_dema, spkr_level_tema, ema_len); - spkr_level_qema = ema(spkr_level_tema, spkr_level_qema, ema_len); - - spkr_level = spkr_level_ema; - - spkr_samples[ spkr_sample_idx++ ] = spkr_level_qema; - spkr_samples[ spkr_sample_idx++ ] = spkr_level_qema; // stereo - } - - spkr_last_level = spkr_level; + spkr_level = level_max; } @@ -527,10 +456,6 @@ float SPKR_INITIAL_TRAILING_EDGE = 0.64; // need a bit of slope to get Xonix so void spkr_toggle() { - // TODO: This is very slow! - -// spkr_play_time = 0; - if ( diskAccelerator_count ) { // turn off disk acceleration immediately diskAccelerator_count = 0; @@ -543,49 +468,42 @@ void spkr_toggle() { // push a click into the speaker buffer // (we will play the entire buffer at the end of the frame) - double indexer = (double)spkr_sample_rate / MHZ(MHz_6502); + double multiplier = (double)spkr_sample_rate / MHZ(MHz_6502); +#ifdef SPKR_KEEP_PITCH if ( MHz_6502 < default_MHz_6502 ) { - indexer = (double)spkr_sample_rate / MHZ(default_MHz_6502); + multiplier = (double)spkr_sample_rate / MHZ(default_MHz_6502); // indexer = (double)spkr_sample_rate / MHZ(default_MHz_6502) * MHz_6502; } +#endif - spkr_sample_idx = round( (double)(spkr_clk + m6502.clkfrm) * indexer ) * SPKR_CHANNELS; + spkr_sample_idx = round( (double)(spkr_clk + m6502.clkfrm) * multiplier ) * SPKR_CHANNELS; spkr_sample_idx &= UINTMAX_MAX - 1; unsigned spkr_sample_idx_diff = spkr_sample_idx - spkr_sample_last_idx; -// if ( (int)spkr_sample_idx_diff == 0 ) { -// // printf("m:%u\n", spkr_sample_idx_diff); -// spkr_sample_idx_diff = UINT_MAX - spkr_sample_idx_diff; -// } + if ( (int)spkr_sample_idx_diff < 0 ) { -// printf("m:%u\n", spkr_sample_idx_diff); spkr_sample_idx_diff = UINT_MAX - spkr_sample_idx_diff; } - spkr_level = spkr_samples[ spkr_sample_idx ]; - if ( spkr_state ) { // down edge spkr_state = 0; - spkr_toggle_edge(SPKR_LEVEL_MIN, SPKR_INITIAL_TRAILING_EDGE, SPKR_FADE_TRAILING_EDGE, spkr_sample_idx_diff); // spkr_toggle_tick(SPKR_LEVEL_MIN, spkr_sample_idx_diff); + spkr_toggle_square(SPKR_LEVEL_MIN, spkr_sample_idx_diff); } else { // up edge spkr_state = 1; - spkr_toggle_edge(SPKR_LEVEL_MAX, SPKR_INITIAL_LEADING_EDGE, SPKR_FADE_LEADING_EDGE, spkr_sample_idx_diff); // spkr_toggle_tick(SPKR_LEVEL_MAX, spkr_sample_idx_diff); + spkr_toggle_square(SPKR_LEVEL_MAX, spkr_sample_idx_diff); } - //spkr_samples[sample_idx] = spkr_level; for ( int i = spkr_sample_idx; i < spkr_buf_size + spkr_extra_buf; i++ ) { spkr_samples[i] = spkr_level; } -// memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_buf_size * sizeof(spkr_sample_t)); - } } @@ -608,6 +526,13 @@ void spkr_update() { if ( ( spkr_play_time ) && ( queued < SPKR_MAX_QUEUED ) ) { if ( freeBuffers ) { + double multiplier = 1; +#ifdef SPKR_KEEP_PITCH + if (MHz_6502 > default_MHz_6502 ) { + multiplier = 1 / MHz_6502; + } +#endif + // in Game Mode do not fade out and stop playing if ( /*( cpuMode_game != cpuMode ) && */( --spkr_play_time == 0 ) ) { @@ -615,84 +540,98 @@ void spkr_update() { printf("freeBuffer < 0 (%i)\n", freeBuffers); freeBuffers = 0; } + + // Need to Cool Down Speaker -- Soft Fade to Zero else { - if ( spkr_samples[0] > 0 ) { + + spkr_fade(spkr_level, 0); + +#ifdef SPKR_DEBUG + fwrite(spkr_samples, sizeof(spkr_sample_t), spkr_buf_size, spkr_debug_file); + fflush(spkr_debug_file); +#endif + + alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, spkr_buf_size * sizeof(spkr_sample_t), spkr_sample_rate); + al_check_error(); + // // DEBUG ONLY!!! // fwrite(spkr_samples + spkr_buf_size * (BUFFER_COUNT - 2), sizeof(spkr_sample_t), spkr_buf_size, af); // fflush(af); - alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples + spkr_buf_size * (BUFFER_COUNT - 2), spkr_buf_size * sizeof(spkr_sample_t), spkr_sample_rate); - al_check_error(); - } - else { -// fwrite(spkr_samples + spkr_buf_size * (BUFFER_COUNT - 1), sizeof(spkr_sample_t), spkr_buf_size, af); -// fflush(af); - - alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples + spkr_buf_size * (BUFFER_COUNT - 1), spkr_buf_size * sizeof(spkr_sample_t), spkr_sample_rate); - al_check_error(); - } - alSourceQueueBuffers(spkr_src[SPKR_SRC_GAME_SFX], 1, &spkr_buffers[freeBuffers]); al_check_error(); + } - memset(spkr_samples, 0, spkr_buf_size * 2 * sizeof(spkr_sample_t)); + memset(spkr_samples, 0, sample_buf_array_len * sizeof(spkr_sample_t)); // spkr_buf_size * sizeof(spkr_sample_t) * SPKR_CHANNELS); spkr_sample_idx = 0; spkr_sample_last_idx = 0; spkr_level = SPKR_LEVEL_ZERO; - spkr_last_level = SPKR_LEVEL_ZERO; - + spkr_level_ema = SPKR_LEVEL_ZERO; + +// spkr_last_level = SPKR_LEVEL_ZERO; } else { - // push a click into the speaker buffer - // (we will play the entire buffer at the end of the frame) - // spkr_sample_idx = ( (spkr_clk + m6502.clkfrm) / ( MHZ(default_MHz_6502) / spkr_sample_rate)) * SPKR_CHANNELS; - - // // DEBUG spike - // spkr_sample_idx = 0; - // spkr_samples[ spkr_sample_idx++ ] = -28000; - // spkr_samples[ spkr_sample_idx++ ] = 28000; // stereo - // spkr_samples[ spkr_sample_idx++ ] = -28000; - // spkr_samples[ spkr_sample_idx++ ] = 28000; // stereo - // spkr_samples[ spkr_sample_idx++ ] = spkr_level; - // spkr_samples[ spkr_sample_idx++ ] = spkr_level; // stereo - - - // //spkr_samples[sample_idx] = spkr_level; - // memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_buf_alloc_size * DEFAULT_FPS - spkr_sample_idx); +// push a click into the speaker buffer +// (we will play the entire buffer at the end of the frame) +// spkr_sample_idx = ( (spkr_clk + m6502.clkfrm) / ( MHZ(default_MHz_6502) / spkr_sample_rate)) * SPKR_CHANNELS; + +// // DEBUG spike +// spkr_sample_idx = 0; +// spkr_samples[ spkr_sample_idx++ ] = -28000; +// spkr_samples[ spkr_sample_idx++ ] = 28000; // stereo +// spkr_samples[ spkr_sample_idx++ ] = -28000; +// spkr_samples[ spkr_sample_idx++ ] = 28000; // stereo +// spkr_samples[ spkr_sample_idx++ ] = spkr_level; +// spkr_samples[ spkr_sample_idx++ ] = spkr_level; // stereo + + +// //spkr_samples[sample_idx] = spkr_level; +// memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_buf_alloc_size * DEFAULT_FPS - spkr_sample_idx); if (--freeBuffers < 0) { printf("freeBuffer < 0 (%i)\n", freeBuffers); freeBuffers = 0; } + + // Normal Sound Buffer Feed else { + // finish the aquare wave + while ( spkr_sample_last_idx < spkr_buf_size ) { + spkr_samples[ spkr_sample_last_idx++ ] = spkr_level; + spkr_samples[ spkr_sample_last_idx++ ] = spkr_level; // stereo + } -// // DEBUG ONLY!!! -// fwrite(spkr_samples, sizeof(spkr_sample_t), (spkr_buf_size + spkr_extra_buf), af); -// fflush(af); -// if (MHz_6502 < default_MHz_6502) { -// size_t size = (spkr_buf_size + spkr_extra_buf) * sizeof(spkr_sample_t); -// memcpy(spkr_samples + size, spkr_samples, size); -// } -// if (MHz_6502 < default_MHz_6502 / 2) { -// size_t size = (spkr_buf_size + spkr_extra_buf) * sizeof(spkr_sample_t) * 2; -// memcpy(spkr_samples + size, spkr_samples, size); -// } + int buf_len = round((double)spkr_buf_size * multiplier + spkr_extra_buf) * sizeof(spkr_sample_t); + +#ifdef SPKR_DEBUG // Debug SPKR Buffer Before EMA +#ifdef SPKR_DEBUG_BEFORE_EMA + fwrite(spkr_samples, 1, buf_len, spkr_debug_file); + fflush(spkr_debug_file); +#endif +#endif - double multiplier = default_MHz_6502 / MHz_6502; - if (MHz_6502 < default_MHz_6502 ) { - multiplier = MHz_6502; + static const int ema_len = 30; // soft: 70; + + int i = 0; + while ( i <= spkr_buf_size ) { + spkr_level_ema = ema(spkr_samples[i], spkr_level_ema, ema_len); + + // super smooth Quadratic EMA + spkr_samples[i++] = spkr_level_ema; + spkr_samples[i++] = spkr_level_ema; } - alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, (spkr_buf_size * multiplier + spkr_extra_buf) * sizeof(spkr_sample_t), spkr_sample_rate * multiplier); -// alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, (spkr_buf_size + spkr_extra_buf) * sizeof(spkr_sample_t), spkr_sample_rate); +#ifdef SPKR_DEBUG // Debug SPKR Buffer After EMA +#ifdef SPKR_DEBUG_AFTER_EMA + fwrite(spkr_samples, 1, buf_len, spkr_debug_file); + fflush(spkr_debug_file); +#endif +#endif - // alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, (spkr_sample_idx + spkr_extra_buf) * sizeof(spkr_sample_t), spkr_sample_rate); - // ALint bufSize = spkr_sample_idx + 20 < spkr_buf_size ? spkr_sample_idx * sizeof(spkr_sample_t) + 20 : spkr_buf_alloc_size; - // alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, bufSize + spkr_extra_buf, spkr_sample_rate); - + alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO16, spkr_samples, buf_len, spkr_sample_rate * multiplier); al_check_error(); alSourceQueueBuffers(spkr_src[SPKR_SRC_GAME_SFX], 1, &spkr_buffers[freeBuffers]); al_check_error(); @@ -701,7 +640,7 @@ void spkr_update() { ALenum state; alGetSourcei( spkr_src[SPKR_SRC_GAME_SFX], AL_SOURCE_STATE, &state ); - // al_check_error(); +// al_check_error(); switch (state) { case AL_PAUSED: @@ -726,56 +665,34 @@ void spkr_update() { break; } - int size = spkr_buf_size + spkr_extra_buf; - int src = size; - int dst = 0; +// int dst = 0; + int src = spkr_buf_size * multiplier + spkr_extra_buf; + int size = max(0, (int)spkr_sample_idx - src); - // copy the buffer leftover -- needed to finish wave form - while( src < spkr_sample_idx ) { - spkr_samples[dst++] = spkr_samples[src++]; + if (size) { + memcpy(spkr_samples, spkr_samples + src * sizeof(spkr_sample_t), size * sizeof(spkr_sample_t) * SPKR_CHANNELS ); } - - // clear the slack buffer, so we can fill it up by new data - while( dst < size ) { - spkr_samples[dst++] = spkr_level; - } - -// float fadeLevel = spkr_level - SPKR_LEVEL_ZERO; -// while ( ( fadeLevel < -1 ) || ( fadeLevel > 1 ) ) { -// spkr_samples[ dst++ ] = SPKR_LEVEL_ZERO + fadeLevel; -// spkr_samples[ dst++ ] = SPKR_LEVEL_ZERO + fadeLevel; // stereo -// -// // how smooth we want the speeker to decay, so we will hear no pops and crackles -// fadeLevel *= 0.999; + + memset(spkr_samples + size, 0, spkr_buf_size * sizeof(spkr_sample_t)); + +// if ( spkr_sample_idx >= size ) { +// spkr_sample_idx -= size; +// } +// else { + spkr_sample_idx = 0; // } -// memcpy( spkr_samples + dst, spkr_samples + src, size * sizeof(spkr_sample_t) * 2 ); - - - // TODO: Problems on Wavy Navy -// if ( ( spkr_sample_idx >= size ) && ( spkr_level == SPKR_LEVEL_ZERO ) ) { - if ( spkr_sample_idx >= size ) { - spkr_sample_idx -= size; - } - else { - spkr_sample_idx = 0; - } - spkr_sample_last_idx = spkr_sample_idx; - - // spkr_samples[0] = 10000; + spkr_sample_last_idx = 0; } else { - printf("No FreeBuffers!\n"); + printf("Warning: No FreeBuffers!\n"); } - // start from the beginning - // spkr_sample_idx = 0; - } - // else { - // printf("spkr_play_time: %u, queued: %i\n", spkr_play_time, queued); - // } +// else { +// printf("spkr_play_time: %u, queued: %i\n", spkr_play_time, queued); +// } spkr_clk = 0; @@ -790,15 +707,9 @@ void spkr_update() { void spkr_playqueue_sfx( ALuint src, uint8_t * sfx, int len ) { - -// printf("%s freeBuffers:%d\n", __FUNCTION__, freeBuffers); - if ( freeBuffers ) { ALenum queued; alGetSourcei( src, AL_BUFFERS_QUEUED, &queued ); - // printf("Q:%u\n", queued); - -// printf("%s queued:%d\n", __FUNCTION__, queued); if ( queued < 16 ) { if (--freeBuffers < 0) { @@ -814,7 +725,7 @@ void spkr_playqueue_sfx( ALuint src, uint8_t * sfx, int len ) { ALenum state; alGetSourcei( src, AL_SOURCE_STATE, &state ); - // al_check_error(); +// al_check_error(); switch (state) { case AL_PLAYING: @@ -831,13 +742,10 @@ void spkr_playqueue_sfx( ALuint src, uint8_t * sfx, int len ) { void spkr_play_sfx( ALuint src, uint8_t * sfx, int len ) { - -// printf("%s freeBuffers:%d\n", __FUNCTION__, freeBuffers); - if ( freeBuffers ) { ALenum state; alGetSourcei( src, AL_SOURCE_STATE, &state ); - // al_check_error(); +// al_check_error(); switch (state) { case AL_PAUSED: