Skip to content

Add support for waveform snapshots#1

Merged
jcavar merged 8 commits intomainfrom
feature/waveform
Apr 4, 2025
Merged

Add support for waveform snapshots#1
jcavar merged 8 commits intomainfrom
feature/waveform

Conversation

@jcavar
Copy link
Collaborator

@jcavar jcavar commented Mar 28, 2025

This PR adds support for waveform snapshots on AVAudioPCMBuffer.

Additionally:

  • Add required resources for testing
  • Add tests for basic waveform types
  • Add README according to our open-source template

@jcavar jcavar force-pushed the feature/waveform branch 4 times, most recently from 1017350 to f40f08f Compare March 28, 2025 09:36
This commit adds a support for waveform snapshots on AVAudioPCMBuffer.

Additionally:
- Add required resources for testing
- Add tests for basic waveform types
@jcavar jcavar force-pushed the feature/waveform branch from f40f08f to 08d195e Compare March 28, 2025 09:45
@jcavar jcavar changed the title Initial commit Add support for waveform snapshots Mar 28, 2025
@jcavar jcavar marked this pull request as ready for review March 28, 2025 09:50
@jcavar jcavar requested a review from hhrvoic March 28, 2025 09:50
Copy link
Contributor

@hhrvoic hhrvoic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, added minor cosmetic comments 🙌

let waveform2 = WaveformView(
buckets: data2,
absMax: max2,
height: CGFloat(height - 8),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have those -8 corrections?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because of padding. I extracted it into a variable and calculate height taking it into account.

Comment on lines +43 to +44
let newFormat = AVAudioFormat(standardFormatWithSampleRate: format.sampleRate, channels: 1)!
let buffer = AVAudioPCMBuffer(pcmFormat: newFormat, frameCapacity: frameLength)!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use guard let here to safely unwrap those format/buffer vars

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

let buffer = AVAudioPCMBuffer(pcmFormat: newFormat, frameCapacity: frameLength)!
buffer.frameLength = frameLength
let stride = vDSP_Stride(1)
let result = buffer.floatChannelData![0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also here we could use if/guard let

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

jcavar and others added 7 commits April 4, 2025 08:45
Co-authored-by: Hrvoje Hrvoić <hrvoje.hrvoic@infinum.hr>
Co-authored-by: Hrvoje Hrvoić <hrvoje.hrvoic@infinum.hr>
Co-authored-by: Hrvoje Hrvoić <hrvoje.hrvoic@infinum.hr>
Co-authored-by: Hrvoje Hrvoić <hrvoje.hrvoic@infinum.hr>
@jcavar jcavar merged commit 3a76f38 into main Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants