From 10392e8260c2477d48b1a5a960f42e524a48be56 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Sun, 21 Apr 2013 17:29:32 -0700 Subject: [PATCH] Add beginnings of lfo, fast exp This patch adds the low-level implementation of an LFO, with the DX7 waveforms, but doesn't yet contain the note wiring. It also adds a fast lookup table based exp function, which is mostly used for envelopes. There are also some build tweaks. It's possible some build files are out of sync with the source, but at least the Android app seems to build. --- cpp/README | 4 + cpp/src/SynthApp.xcodeproj/project.pbxproj | 123 ++++++++++----------- cpp/src/core.gyp | 3 + cpp/src/core.xcodeproj/project.pbxproj | 84 +++++++------- cpp/src/exp2.cc | 36 ++++++ cpp/src/exp2.h | 46 ++++++++ cpp/src/lfo.cc | 69 ++++++++++++ cpp/src/lfo.h | 36 ++++++ cpp/src/main.cc | 15 +++ 9 files changed, 313 insertions(+), 103 deletions(-) create mode 100644 cpp/src/exp2.cc create mode 100644 cpp/src/exp2.h create mode 100644 cpp/src/lfo.cc create mode 100644 cpp/src/lfo.h diff --git a/cpp/README b/cpp/README index 5d29905..e715643 100644 --- a/cpp/README +++ b/cpp/README @@ -18,3 +18,7 @@ The File Open menu command is hooked up as well and will load SYX format DX7 patch files (32 patches per file). Send program change midi events with the first 32 program numbers. +The xcodeproj files are checked into the repo, but they are autogenerated +from .gyp files, which are the authoritative masters. To modify the +build, change the .gyp file, then run "gyp" in this dir. For changes +to the core, also change ../../android/jni/Android.mk . \ No newline at end of file diff --git a/cpp/src/SynthApp.xcodeproj/project.pbxproj b/cpp/src/SynthApp.xcodeproj/project.pbxproj index 64f76c0..8fa6c11 100644 --- a/cpp/src/SynthApp.xcodeproj/project.pbxproj +++ b/cpp/src/SynthApp.xcodeproj/project.pbxproj @@ -7,20 +7,20 @@ objects = { /* Begin PBXBuildFile section */ - 070048C57FCB5F31827D61CD /* midi_in_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9CC658C4805259001BB2BA70 /* midi_in_mac.cc */; }; - 444FC1A8A4F4BFBB71A55578 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 106567A2B2FDE65A2547B9C0 /* InfoPlist.strings */; }; - 4EC6E0A88AFE158936E7DF22 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3EDCE57490308092B70255E /* CoreFoundation.framework */; }; - 6004825C9C1BA9246F032431 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D3126A377165245C44B6C8A /* CoreAudio.framework */; }; - 6824545AE8F4DAFB95F6CDDB /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB723D6CDE6B962FBA69894 /* main.m */; }; - 752469DD01013D889966B42C /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F664EAAFF41058799553650 /* AudioUnit.framework */; }; - 7E84D499B82B6C02EB8AA96C /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = D651559601BF84BEA261778D /* MainMenu.xib */; }; - 7F9707F48C04E2AE1EB5C866 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4618975BF19F21FC2A429474 /* Cocoa.framework */; }; - 9366D617A2CE978AEA3555B3 /* libcore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BACEAAFABBABE1D12902220B /* libcore.a */; }; - 982E3B747974F63D8B4482B2 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9DC34125BEDD68ABCAB055D /* AudioToolbox.framework */; }; - 98F8F0314510BD0F6AA320CE /* SynthMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = AFA13CCA8E0B32555D59A9B3 /* SynthMain.mm */; }; - B6BA9FF151AD9A0D309C0D53 /* CoreMIDI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B1680278C574FAEFF7657992 /* CoreMIDI.framework */; }; - C5E74E9A85CDC29EB3DCCBF7 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0638CA1C453E326E762DA4BE /* Carbon.framework */; }; - D6CAF0C6797908C34B18E987 /* SynthAppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 22758A226C30B8A0C2E095B2 /* SynthAppDelegate.mm */; }; + 0AF9B4E130CD067B67982EBD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB723D6CDE6B962FBA69894 /* main.m */; }; + 1C5DE660EC77BB10207B2287 /* SynthMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = AFA13CCA8E0B32555D59A9B3 /* SynthMain.mm */; }; + 2BA8FE676832264E0511D537 /* midi_in_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9CC658C4805259001BB2BA70 /* midi_in_mac.cc */; }; + 5EAECBD70CBEA73B2779206F /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0638CA1C453E326E762DA4BE /* Carbon.framework */; }; + 8F78BB0F8E5ABD62E94E9033 /* libcore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BACEAAFABBABE1D12902220B /* libcore.a */; }; + 934113319D00751E8E25D151 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9DC34125BEDD68ABCAB055D /* AudioToolbox.framework */; }; + 99BC8AF04EDB098B35258E82 /* SynthAppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 22758A226C30B8A0C2E095B2 /* SynthAppDelegate.mm */; }; + B4DE673655497871A3BBC156 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3EDCE57490308092B70255E /* CoreFoundation.framework */; }; + D19B14BE69AE22E170B65E39 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D3126A377165245C44B6C8A /* CoreAudio.framework */; }; + D981AAA9AAF8D88A04A6C48B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3E06DBD96E36EB93BEA0FC1B /* InfoPlist.strings */; }; + E55D320615482E26123191C2 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F664EAAFF41058799553650 /* AudioUnit.framework */; }; + F7624EA1A8133B1F867A515E /* CoreMIDI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B1680278C574FAEFF7657992 /* CoreMIDI.framework */; }; + FB09285A67966501565CC485 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = CF2DC82EE50B750198149118 /* MainMenu.xib */; }; + FEDE0E473529E7B58EAA6CF3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4618975BF19F21FC2A429474 /* Cocoa.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -65,54 +65,51 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9366D617A2CE978AEA3555B3 /* libcore.a in Frameworks */, - 982E3B747974F63D8B4482B2 /* AudioToolbox.framework in Frameworks */, - 752469DD01013D889966B42C /* AudioUnit.framework in Frameworks */, - C5E74E9A85CDC29EB3DCCBF7 /* Carbon.framework in Frameworks */, - 7F9707F48C04E2AE1EB5C866 /* Cocoa.framework in Frameworks */, - 6004825C9C1BA9246F032431 /* CoreAudio.framework in Frameworks */, - 4EC6E0A88AFE158936E7DF22 /* CoreFoundation.framework in Frameworks */, - B6BA9FF151AD9A0D309C0D53 /* CoreMIDI.framework in Frameworks */, + 8F78BB0F8E5ABD62E94E9033 /* libcore.a in Frameworks */, + 934113319D00751E8E25D151 /* AudioToolbox.framework in Frameworks */, + E55D320615482E26123191C2 /* AudioUnit.framework in Frameworks */, + 5EAECBD70CBEA73B2779206F /* Carbon.framework in Frameworks */, + FEDE0E473529E7B58EAA6CF3 /* Cocoa.framework in Frameworks */, + D19B14BE69AE22E170B65E39 /* CoreAudio.framework in Frameworks */, + B4DE673655497871A3BBC156 /* CoreFoundation.framework in Frameworks */, + F7624EA1A8133B1F867A515E /* CoreMIDI.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 08D7B67857704EB61BBC1112 /* Frameworks */ = { + 048E2E4F06C19059DA10948A /* Products */ = { isa = PBXGroup; children = ( - F9DC34125BEDD68ABCAB055D /* AudioToolbox.framework */, - 6F664EAAFF41058799553650 /* AudioUnit.framework */, - 0638CA1C453E326E762DA4BE /* Carbon.framework */, - 4618975BF19F21FC2A429474 /* Cocoa.framework */, - 2D3126A377165245C44B6C8A /* CoreAudio.framework */, - C3EDCE57490308092B70255E /* CoreFoundation.framework */, - B1680278C574FAEFF7657992 /* CoreMIDI.framework */, + E4B4F7598D96CC2CE29666B4 /* SynthApp.app */, ); - name = Frameworks; + name = Products; sourceTree = ""; }; - 26BC9EF25519FDFECC66EBA5 /* Products */ = { + 06DC9AAFE57AC70F6D82C9B8 /* Products */ = { isa = PBXGroup; children = ( - E4B4F7598D96CC2CE29666B4 /* SynthApp.app */, + BACEAAFABBABE1D12902220B /* libcore.a */, ); name = Products; sourceTree = ""; }; - 56669AEF9C728CE587C3E8A3 = { + 571F3C9918276141BDFD1F04 /* Frameworks */ = { isa = PBXGroup; children = ( - C611344839FF3B4608474E37 /* Source */, - 710624B4F3ADB1F020942DB0 /* Projects */, - 08D7B67857704EB61BBC1112 /* Frameworks */, - 26BC9EF25519FDFECC66EBA5 /* Products */, - FF670D1787E80284877493D1 /* Build */, + F9DC34125BEDD68ABCAB055D /* AudioToolbox.framework */, + 6F664EAAFF41058799553650 /* AudioUnit.framework */, + 0638CA1C453E326E762DA4BE /* Carbon.framework */, + 4618975BF19F21FC2A429474 /* Cocoa.framework */, + 2D3126A377165245C44B6C8A /* CoreAudio.framework */, + C3EDCE57490308092B70255E /* CoreFoundation.framework */, + B1680278C574FAEFF7657992 /* CoreMIDI.framework */, ); + name = Frameworks; sourceTree = ""; }; - 710624B4F3ADB1F020942DB0 /* Projects */ = { + 652E39EBA60801294DEE7827 /* Projects */ = { isa = PBXGroup; children = ( B5F1A11C57F7DE82D8F9F9C2 /* core.xcodeproj */, @@ -120,11 +117,11 @@ name = Projects; sourceTree = ""; }; - C611344839FF3B4608474E37 /* Source */ = { + 8C541AB012A6421C156ED3CC /* Source */ = { isa = PBXGroup; children = ( - 106567A2B2FDE65A2547B9C0 /* InfoPlist.strings */, - D651559601BF84BEA261778D /* MainMenu.xib */, + 3E06DBD96E36EB93BEA0FC1B /* InfoPlist.strings */, + CF2DC82EE50B750198149118 /* MainMenu.xib */, 22758A226C30B8A0C2E095B2 /* SynthAppDelegate.mm */, 3C854865960DE58DBB62E200 /* SynthApp_Prefix.pch */, AFA13CCA8E0B32555D59A9B3 /* SynthMain.mm */, @@ -135,20 +132,23 @@ path = SynthApp; sourceTree = ""; }; - D9149B7557AF29282FBD3555 /* Products */ = { + AE142D1365FF48FD556E86BC /* Build */ = { isa = PBXGroup; children = ( - BACEAAFABBABE1D12902220B /* libcore.a */, + 645192D86D7D39B0CAB2E0FC /* SynthApp.gyp */, ); - name = Products; + name = Build; sourceTree = ""; }; - FF670D1787E80284877493D1 /* Build */ = { + EEAFDBA4970041AA25C22652 = { isa = PBXGroup; children = ( - 645192D86D7D39B0CAB2E0FC /* SynthApp.gyp */, + 8C541AB012A6421C156ED3CC /* Source */, + 652E39EBA60801294DEE7827 /* Projects */, + 571F3C9918276141BDFD1F04 /* Frameworks */, + 048E2E4F06C19059DA10948A /* Products */, + AE142D1365FF48FD556E86BC /* Build */, ); - name = Build; sourceTree = ""; }; /* End PBXGroup section */ @@ -185,16 +185,13 @@ developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( - English, - Japanese, - French, - German, + en, ); - mainGroup = 56669AEF9C728CE587C3E8A3; + mainGroup = EEAFDBA4970041AA25C22652; projectDirPath = ""; projectReferences = ( { - ProductGroup = D9149B7557AF29282FBD3555 /* Products */; + ProductGroup = 06DC9AAFE57AC70F6D82C9B8 /* Products */; ProjectRef = B5F1A11C57F7DE82D8F9F9C2 /* core.xcodeproj */; }, ); @@ -220,8 +217,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 444FC1A8A4F4BFBB71A55578 /* InfoPlist.strings in Resources */, - 7E84D499B82B6C02EB8AA96C /* MainMenu.xib in Resources */, + D981AAA9AAF8D88A04A6C48B /* InfoPlist.strings in Resources */, + FB09285A67966501565CC485 /* MainMenu.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -232,10 +229,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 6824545AE8F4DAFB95F6CDDB /* main.m in Sources */, - 070048C57FCB5F31827D61CD /* midi_in_mac.cc in Sources */, - D6CAF0C6797908C34B18E987 /* SynthAppDelegate.mm in Sources */, - 98F8F0314510BD0F6AA320CE /* SynthMain.mm in Sources */, + 0AF9B4E130CD067B67982EBD /* main.m in Sources */, + 2BA8FE676832264E0511D537 /* midi_in_mac.cc in Sources */, + 99BC8AF04EDB098B35258E82 /* SynthAppDelegate.mm in Sources */, + 1C5DE660EC77BB10207B2287 /* SynthMain.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -250,7 +247,7 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ - 106567A2B2FDE65A2547B9C0 /* InfoPlist.strings */ = { + 3E06DBD96E36EB93BEA0FC1B /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( AC00D3CE197617EB5BC7110C /* English */, @@ -258,7 +255,7 @@ name = InfoPlist.strings; sourceTree = ""; }; - D651559601BF84BEA261778D /* MainMenu.xib */ = { + CF2DC82EE50B750198149118 /* MainMenu.xib */ = { isa = PBXVariantGroup; children = ( 47E3EC1A3593850470FB7E33 /* English */, diff --git a/cpp/src/core.gyp b/cpp/src/core.gyp index ae9fca8..cd0f8d1 100644 --- a/cpp/src/core.gyp +++ b/cpp/src/core.gyp @@ -6,9 +6,12 @@ 'sources': [ 'dx7note.cc', 'env.cc', + 'exp2.cc', 'fm_core.cc', 'fm_op_kernel.cc', 'freqlut.cc', + 'lfo.cc', + 'patch.cc', 'resofilter.cc', 'ringbuffer.cc', 'sawtooth.cc', diff --git a/cpp/src/core.xcodeproj/project.pbxproj b/cpp/src/core.xcodeproj/project.pbxproj index 4f5112d..04cf8c3 100644 --- a/cpp/src/core.xcodeproj/project.pbxproj +++ b/cpp/src/core.xcodeproj/project.pbxproj @@ -3,38 +3,42 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 45; objects = { /* Begin PBXBuildFile section */ - 1DBA85B761236957DF00CF7B /* fm_core.cc in Sources */ = {isa = PBXBuildFile; fileRef = DA7AAEE2AD874001F6B71D52 /* fm_core.cc */; }; - 2FB5AF9855596821669CAE1F /* dx7note.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA00975977E2704F74104728 /* dx7note.cc */; }; - 36D08A0FEA591FC0EF188469 /* env.cc in Sources */ = {isa = PBXBuildFile; fileRef = B73D485E55EBD9CD5950A375 /* env.cc */; }; - 4FB7FFF436D333023EC91E2C /* sin.cc in Sources */ = {isa = PBXBuildFile; fileRef = D1D8B6FB01C9E7E2D99378F0 /* sin.cc */; }; - 5FA224E159A6B07188657BA8 /* freqlut.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9FF02D488CE6FD5017D7D81A /* freqlut.cc */; }; - 71911D7305F0175DC4A3FF17 /* sawtooth.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48B6535400CF3AC8BABB3299 /* sawtooth.cc */; }; - 80D3C6DC6F5236826B6AB404 /* test_ringbuffer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 521793C71CAA078F5598EFC0 /* test_ringbuffer.cc */; }; - 8D41064389CC8FD281956BF7 /* fm_op_kernel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 509D811344DB98984FD6C126 /* fm_op_kernel.cc */; }; - 908EAB1EE59231C41FD88BCD /* ringbuffer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 68FD17910F296961541A67E4 /* ringbuffer.cc */; }; - A16F70FD02394895C6FA7326 /* synth_unit.cc in Sources */ = {isa = PBXBuildFile; fileRef = 2082841A11DF6E62596265CF /* synth_unit.cc */; }; - AECC016D16C70F9300FBD4E4 /* patch.cc in Sources */ = {isa = PBXBuildFile; fileRef = AECC016C16C70F9300FBD4E4 /* patch.cc */; }; - D5ECD09EBEB1684C00616248 /* resofilter.cc in Sources */ = {isa = PBXBuildFile; fileRef = 97A5CBACD479212282D0BFD6 /* resofilter.cc */; }; + 2DD71F3E9AE0C4253B8B7747 /* exp2.cc in Sources */ = {isa = PBXBuildFile; fileRef = D5669C7FDAF95F10639CF5AB /* exp2.cc */; }; + 391223C6D7249361C00A14AF /* dx7note.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA00975977E2704F74104728 /* dx7note.cc */; }; + 3DFFE98F73F04D2F66DA9FA4 /* env.cc in Sources */ = {isa = PBXBuildFile; fileRef = B73D485E55EBD9CD5950A375 /* env.cc */; }; + 50C9BC20B9DB9E51A9B852BC /* test_ringbuffer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 521793C71CAA078F5598EFC0 /* test_ringbuffer.cc */; }; + 6E01450F6BFF126216C8164C /* ringbuffer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 68FD17910F296961541A67E4 /* ringbuffer.cc */; }; + 79D1CB0F9A4671DA79729544 /* fm_op_kernel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 509D811344DB98984FD6C126 /* fm_op_kernel.cc */; }; + 97788F06DA1810835D9F0A50 /* lfo.cc in Sources */ = {isa = PBXBuildFile; fileRef = 42D2A2AD8EDACBEF9B884718 /* lfo.cc */; }; + AA0F43347EBDEE6D29032DAF /* sin.cc in Sources */ = {isa = PBXBuildFile; fileRef = D1D8B6FB01C9E7E2D99378F0 /* sin.cc */; }; + AA1CD32CDCFEB4469067D98E /* resofilter.cc in Sources */ = {isa = PBXBuildFile; fileRef = 97A5CBACD479212282D0BFD6 /* resofilter.cc */; }; + B64D26CA7CC8017052D3E963 /* patch.cc in Sources */ = {isa = PBXBuildFile; fileRef = 779AFCD7AFEB1CDEACBC0425 /* patch.cc */; }; + D80FBC17492647DCFDE96F75 /* fm_core.cc in Sources */ = {isa = PBXBuildFile; fileRef = DA7AAEE2AD874001F6B71D52 /* fm_core.cc */; }; + E2649182D734B708D5E72B66 /* synth_unit.cc in Sources */ = {isa = PBXBuildFile; fileRef = 2082841A11DF6E62596265CF /* synth_unit.cc */; }; + E31A9F6965B9E56115BAE59F /* sawtooth.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48B6535400CF3AC8BABB3299 /* sawtooth.cc */; }; + FB78A2E9904695ABCC799CC3 /* freqlut.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9FF02D488CE6FD5017D7D81A /* freqlut.cc */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 2082841A11DF6E62596265CF /* synth_unit.cc */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = synth_unit.cc; sourceTree = ""; tabWidth = 2; }; + 2082841A11DF6E62596265CF /* synth_unit.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = synth_unit.cc; sourceTree = ""; }; + 42D2A2AD8EDACBEF9B884718 /* lfo.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = lfo.cc; sourceTree = ""; }; 48B6535400CF3AC8BABB3299 /* sawtooth.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = sawtooth.cc; sourceTree = ""; }; 509D811344DB98984FD6C126 /* fm_op_kernel.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = fm_op_kernel.cc; sourceTree = ""; }; 521793C71CAA078F5598EFC0 /* test_ringbuffer.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = test_ringbuffer.cc; sourceTree = ""; }; 68FD17910F296961541A67E4 /* ringbuffer.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ringbuffer.cc; sourceTree = ""; }; 6C1B71FBACD041F20E7F828A /* core.gyp */ = {isa = PBXFileReference; lastKnownFileType = text; path = core.gyp; sourceTree = ""; }; + 779AFCD7AFEB1CDEACBC0425 /* patch.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = patch.cc; sourceTree = ""; }; 8B1FC9FF853D5C32F4771091 /* libcore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcore.a; sourceTree = BUILT_PRODUCTS_DIR; }; 97A5CBACD479212282D0BFD6 /* resofilter.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = resofilter.cc; sourceTree = ""; }; 9FF02D488CE6FD5017D7D81A /* freqlut.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = freqlut.cc; sourceTree = ""; }; - AECC016C16C70F9300FBD4E4 /* patch.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = patch.cc; sourceTree = ""; }; B73D485E55EBD9CD5950A375 /* env.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = env.cc; sourceTree = ""; }; BA00975977E2704F74104728 /* dx7note.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = dx7note.cc; sourceTree = ""; }; D1D8B6FB01C9E7E2D99378F0 /* sin.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = sin.cc; sourceTree = ""; }; + D5669C7FDAF95F10639CF5AB /* exp2.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = exp2.cc; sourceTree = ""; }; DA7AAEE2AD874001F6B71D52 /* fm_core.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = fm_core.cc; sourceTree = ""; }; /* End PBXFileReference section */ @@ -49,24 +53,26 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 1CE02724939AB46300B24440 = { + 19BC3E7E3EDF760717F26DF5 = { isa = PBXGroup; children = ( - AECC016C16C70F9300FBD4E4 /* patch.cc */, - 521E615727EAD5BFC2BFE8C3 /* Source */, - ADABDC1FC75C07B5469F92DE /* Products */, - 72A5A7469C1AF9FDDAB23BD1 /* Build */, + 1B875637F4FC04501E9170B8 /* Source */, + E53EB7DD466ADEEC9F094623 /* Products */, + 8512968DD6AB145582824E65 /* Build */, ); sourceTree = ""; }; - 521E615727EAD5BFC2BFE8C3 /* Source */ = { + 1B875637F4FC04501E9170B8 /* Source */ = { isa = PBXGroup; children = ( BA00975977E2704F74104728 /* dx7note.cc */, B73D485E55EBD9CD5950A375 /* env.cc */, + D5669C7FDAF95F10639CF5AB /* exp2.cc */, DA7AAEE2AD874001F6B71D52 /* fm_core.cc */, 509D811344DB98984FD6C126 /* fm_op_kernel.cc */, 9FF02D488CE6FD5017D7D81A /* freqlut.cc */, + 42D2A2AD8EDACBEF9B884718 /* lfo.cc */, + 779AFCD7AFEB1CDEACBC0425 /* patch.cc */, 97A5CBACD479212282D0BFD6 /* resofilter.cc */, 68FD17910F296961541A67E4 /* ringbuffer.cc */, 48B6535400CF3AC8BABB3299 /* sawtooth.cc */, @@ -77,7 +83,7 @@ name = Source; sourceTree = ""; }; - 72A5A7469C1AF9FDDAB23BD1 /* Build */ = { + 8512968DD6AB145582824E65 /* Build */ = { isa = PBXGroup; children = ( 6C1B71FBACD041F20E7F828A /* core.gyp */, @@ -85,7 +91,7 @@ name = Build; sourceTree = ""; }; - ADABDC1FC75C07B5469F92DE /* Products */ = { + E53EB7DD466ADEEC9F094623 /* Products */ = { isa = PBXGroup; children = ( 8B1FC9FF853D5C32F4771091 /* libcore.a */, @@ -122,12 +128,8 @@ }; buildConfigurationList = 2F684B8427DC8F5001D9A5B0 /* Build configuration list for PBXProject "core" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; hasScannedForEncodings = 1; - knownRegions = ( - en, - ); - mainGroup = 1CE02724939AB46300B24440; + mainGroup = 19BC3E7E3EDF760717F26DF5; projectDirPath = ""; projectRoot = ""; targets = ( @@ -141,18 +143,20 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2FB5AF9855596821669CAE1F /* dx7note.cc in Sources */, - 36D08A0FEA591FC0EF188469 /* env.cc in Sources */, - 1DBA85B761236957DF00CF7B /* fm_core.cc in Sources */, - 8D41064389CC8FD281956BF7 /* fm_op_kernel.cc in Sources */, - 5FA224E159A6B07188657BA8 /* freqlut.cc in Sources */, - D5ECD09EBEB1684C00616248 /* resofilter.cc in Sources */, - 908EAB1EE59231C41FD88BCD /* ringbuffer.cc in Sources */, - 71911D7305F0175DC4A3FF17 /* sawtooth.cc in Sources */, - 4FB7FFF436D333023EC91E2C /* sin.cc in Sources */, - A16F70FD02394895C6FA7326 /* synth_unit.cc in Sources */, - 80D3C6DC6F5236826B6AB404 /* test_ringbuffer.cc in Sources */, - AECC016D16C70F9300FBD4E4 /* patch.cc in Sources */, + 391223C6D7249361C00A14AF /* dx7note.cc in Sources */, + 3DFFE98F73F04D2F66DA9FA4 /* env.cc in Sources */, + 2DD71F3E9AE0C4253B8B7747 /* exp2.cc in Sources */, + D80FBC17492647DCFDE96F75 /* fm_core.cc in Sources */, + 79D1CB0F9A4671DA79729544 /* fm_op_kernel.cc in Sources */, + FB78A2E9904695ABCC799CC3 /* freqlut.cc in Sources */, + 97788F06DA1810835D9F0A50 /* lfo.cc in Sources */, + B64D26CA7CC8017052D3E963 /* patch.cc in Sources */, + AA1CD32CDCFEB4469067D98E /* resofilter.cc in Sources */, + 6E01450F6BFF126216C8164C /* ringbuffer.cc in Sources */, + E31A9F6965B9E56115BAE59F /* sawtooth.cc in Sources */, + AA0F43347EBDEE6D29032DAF /* sin.cc in Sources */, + E2649182D734B708D5E72B66 /* synth_unit.cc in Sources */, + 50C9BC20B9DB9E51A9B852BC /* test_ringbuffer.cc in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cpp/src/exp2.cc b/cpp/src/exp2.cc new file mode 100644 index 0000000..7f3a93d --- /dev/null +++ b/cpp/src/exp2.cc @@ -0,0 +1,36 @@ +/* + * Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "synth.h" +#include "exp2.h" + +int32_t exp2tab[EXP2_N_SAMPLES << 1]; + +void Exp2::init() { + double inc = exp2(1.0 / EXP2_N_SAMPLES); + double y = 1 << 30; + for (int i = 0; i < EXP2_N_SAMPLES; i++) { + exp2tab[(i << 1) + 1] = (int32_t)floor(y + 0.5); + y *= inc; + } + for (int i = 0; i < EXP2_N_SAMPLES - 1; i++) { + exp2tab[i << 1] = exp2tab[(i << 1) + 3] - exp2tab[(i << 1) + 1]; + } + exp2tab[(EXP2_N_SAMPLES << 1) - 2] = (1U << 31) - exp2tab[(EXP2_N_SAMPLES << 1) - 1]; +} + diff --git a/cpp/src/exp2.h b/cpp/src/exp2.h new file mode 100644 index 0000000..2c08fb1 --- /dev/null +++ b/cpp/src/exp2.h @@ -0,0 +1,46 @@ +/* + * Copyright 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class Exp2 { + public: + Exp2(); + + static void init(); + + // Q24 in, Q24 out + static int32_t lookup(int32_t x); +}; + +#define EXP2_LG_N_SAMPLES 10 +#define EXP2_N_SAMPLES (1 << EXP2_LG_N_SAMPLES) + +#define EXP2_INLINE + +extern int32_t exp2tab[EXP2_N_SAMPLES << 1]; + +#ifdef EXP2_INLINE +inline +int32_t Exp2::lookup(int32_t x) { + const int SHIFT = 24 - EXP2_LG_N_SAMPLES; + int lowbits = x & ((1 << SHIFT) - 1); + int x_int = (x >> (SHIFT - 1)) & ((EXP2_N_SAMPLES - 1) << 1); + int dy = exp2tab[x_int]; + int y0 = exp2tab[x_int + 1]; + + int y = y0 + (((int64_t)dy * (int64_t)lowbits) >> SHIFT); + return y >> (6 - (x >> 24)); +} +#endif diff --git a/cpp/src/lfo.cc b/cpp/src/lfo.cc new file mode 100644 index 0000000..4089ae4 --- /dev/null +++ b/cpp/src/lfo.cc @@ -0,0 +1,69 @@ +/* + * Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Low frequency oscillator, compatible with DX7 + +#include "synth.h" + +#include "sin.h" +#include "lfo.h" + +void Lfo::init(double sample_rate) { + // constant is 1 << 32 / 15.5s / 11 + Lfo::unit_ = (int32_t)(N * 25190424 / sample_rate + 0.5); +} + +void Lfo::reset(const char params[6]) { + int rate = params[0]; // 0..99 + int sr = rate == 0 ? 1 : (165 * rate) >> 6; + sr *= sr < 160 ? 11 : (11 + ((sr - 160) >> 4)); + delta_ = unit_ * sr; + waveform_ = params[5]; + sync_ = params[4] != 0; +} + +int32_t Lfo::getsample() { + phase_ += delta_; + int32_t x; + switch (waveform_) { + case 0: // triangle + x = phase_ >> 7; + x ^= -(phase_ >> 31); + x &= (1 << 24) - 1; + return x; + case 1: // sawtooth down + return (~phase_ ^ (1U << 31)) >> 8; + case 2: // sawtooth up + return (phase_ ^ (1U << 31)) >> 8; + case 3: // square + return ((~phase_) >> 7) & (1 << 24); + case 4: // sine + return (1 << 23) + (Sin::lookup(phase_ >> 8) >> 1); + case 5: // s&h + if (phase_ < delta_) { + randstate_ = (randstate_ * 179 + 17) & 0xff; + } + x = randstate_ ^ 0x80; + return (x + 1) << 16; + } + return 1 << 23; +} + +void Lfo::keydown() { + if (sync_) { + phase_ = (1U << 31) - 1; + } +} diff --git a/cpp/src/lfo.h b/cpp/src/lfo.h new file mode 100644 index 0000000..18f4f70 --- /dev/null +++ b/cpp/src/lfo.h @@ -0,0 +1,36 @@ +/* + * Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Low frequency oscillator, compatible with DX7 + +class Lfo { + public: + static void init(double sample_rate); + void reset(const char params[6]); + + // result is 0..1 in Q24 + int32_t getsample(); + + void keydown(); + private: + static uint32_t unit_; + + uint32_t phase_; // Q32 + uint32_t delta_; + uint8_t waveform_; + uint8_t randstate_; + bool sync_; +}; diff --git a/cpp/src/main.cc b/cpp/src/main.cc index b0b44b9..f3be631 100644 --- a/cpp/src/main.cc +++ b/cpp/src/main.cc @@ -24,6 +24,7 @@ #include "wavout.h" #include "sawtooth.h" #include "sin.h" +#include "exp2.h" #include "resofilter.h" #include "fm_core.h" #include "fm_op_kernel.h" @@ -217,11 +218,24 @@ void mkdx7note(double sample_rate) { void test_ringbuffer(); +void test_exp2() { + for (int32_t i = -16 << 24; i < 6 << 24; i += 123) { + int32_t result = Exp2::lookup(i); + int32_t accurate = floor((1<<24) * pow(2, i * 1.0 / (1<<24)) + .5); + int32_t error = accurate - result; + if (abs(error) > 1 && abs(error) > accurate / 10000000) { + std::cout << i << ": " << result << " " << accurate << std::endl; + // TODO (maybe): hook into automated test runner & report results + } + } +} + int main(int argc, char **argv) { double sample_rate = 44100.0; Freqlut::init(sample_rate); Sawtooth::init(sample_rate); Sin::init(); + Exp2::init(); //FmCore::dump(); //test_sin_accuracy(); @@ -234,5 +248,6 @@ int main(int argc, char **argv) { //mkdx7note(sample_rate); mksaw(sample_rate); //test_ringbuffer(); + test_exp2(); return 0; }