Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio is trimmed when converting from PCM to Ogg #23

Open
StephenHodgson opened this issue May 23, 2024 · 2 comments · May be fixed by #24
Open

Audio is trimmed when converting from PCM to Ogg #23

StephenHodgson opened this issue May 23, 2024 · 2 comments · May be fixed by #24
Assignees
Labels
bug Something isn't working

Comments

@StephenHodgson
Copy link
Member

Bug Report

To Reproduce

Steps to reproduce the behavior:

    public static void ConvertWavToOgg()
    {
        Debug.Log("Convert WAV to OGG");
        // Open file dialog to select a WAV file
        string wavPath = EditorUtility.OpenFilePanel("Select WAV file", "", "wav");
        Assert.IsNotNull(wavPath);

        AudioClip wavAudioClip = LoadAudioFile(wavPath, AudioType.WAV);
        Assert.AreEqual(1, wavAudioClip.channels, "Only mono audio is supported");

        // Convert the audio clip to OGG
        string oggPath = wavPath.Replace(".wav", ".ogg");
        var pcmData = new float[wavAudioClip.samples];
        wavAudioClip.GetData(pcmData, 0);
        var oggBytes = OggEncoder.ConvertToBytes(pcmData, wavAudioClip.frequency, 1);
        File.WriteAllBytes(oggPath, oggBytes);


        // Reload ogg file
        AudioClip oggAudioClip = LoadAudioFile(oggPath, AudioType.OGGVORBIS);

        Assert.AreEqual(wavAudioClip.samples, oggAudioClip.samples, $"Sample count mismatch: wav={wavAudioClip.samples}, ogg={oggAudioClip.samples}");
    }
@StephenHodgson StephenHodgson added the bug Something isn't working label May 23, 2024
@StephenHodgson StephenHodgson self-assigned this May 23, 2024
@StephenHodgson
Copy link
Member Author

@StephenHodgson StephenHodgson linked a pull request May 23, 2024 that will close this issue
@StephenHodgson
Copy link
Member Author

Found a possible replacement: https://github.com/NVorbis/NVorbis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant