Coder Social home page Coder Social logo

xsmetronome's Introduction

XSMetronome

iOS Build Status tvOS Build Status

Simple demonstration of a metronome using AVAudioEngine and AVAudioPlayerNode to schedule buffers for timing accurate playback using scheduleBuffer:atTime:options:completionHandler:. The implementation also provides for a delegate object to call with the method (metronomeTicking:bar:beat:) which can be used for timing or to provide UI.

Main Files

Metronome.swift

  • Source file for metronome implementation in all the targets.

TWGenerator.swift

  • Generic TriangleWaveGenerator swift class used by all targets.

Version History

1.0 Initial release.

Requirements

Build

Xcode 8.2.1 or later, macOS 10.12, iOS 10.2, watchOS 3.1 SDKs

Runtime

macOS 10.9 or greater iOS 11.0 or greater watchOS 4 or greater

xsmetronome's People

Contributors

xiangyu-sun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lxirsh logg926

xsmetronome's Issues

Using an audio file for the sound

Thanks for making this! I'm interested in using an audio file for the click sound rather than a generated triangle wave, but it doesn't seem to work.

The change (also using only one sound rather than 2):

    let clickURL = Bundle.main.url(forResource: "metronome.click", withExtension: "wav")!
    let audioFile = try! AVAudioFile(forReading: clickURL)
    let audioFormat = audioFile.processingFormat
    let audioFrameCount = UInt32(audioFile.length)

    audioBuffer = AVAudioPCMBuffer(pcmFormat: audioFormat, frameCapacity: audioFrameCount)
    audioBuffer.frameLength = audioFrameCount
    try! audioFile.read(into: audioBuffer!)
    
    self.audioFormat = buffers[0]!.format
    self.bufferSampleRate = audioFormat.sampleRate
    
    initiazeDefaults()

    engine.attach(player)
    engine.connect(player, to:  engine.outputNode, fromBus: 0, toBus: 0, format: audioFormat)

This works perfectly at BPMs below 90 or so, but as the BPM increases the clicks get quieter and quieter until they disappear. Any thoughts on how to support audio files?

EDIT: Sound file works if it's 0.02 seconds in duration or less it seems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.