mpg123_id3() private method

private mpg123_id3 ( IntPtr mh, IntPtr &v1, IntPtr &v2 ) : int
mh IntPtr
v1 IntPtr
v2 IntPtr
return int
    public void StartImport(String mPath)
    {
        source = (AudioSource)gameObject.GetComponent(typeof(AudioSource));
        if (source == null)
        {
            source = (AudioSource)gameObject.AddComponent <AudioSource>();
        }
        MPGImport.mpg123_init();
        handle_mpg = MPGImport.mpg123_new(null, errPtr);
        x          = MPGImport.mpg123_open(handle_mpg, mPath);
        MPGImport.mpg123_getformat(handle_mpg, out rate, out channels, out encoding);
        intRate     = rate.ToInt32();
        intChannels = channels.ToInt32();
        intEncoding = encoding.ToInt32();

        MPGImport.mpg123_id3(handle_mpg, out id3v1, out id3v2);
        MPGImport.mpg123_format_none(handle_mpg);
        MPGImport.mpg123_format(handle_mpg, intRate, intChannels, 208);

        FrameSize = MPGImport.mpg123_outblock(handle_mpg);
        byte[] Buffer = new byte[FrameSize];
        lengthSamples = MPGImport.mpg123_length(handle_mpg);

        myClip = AudioClip.Create("myClip", lengthSamples, intChannels, intRate, false, false);

        int importIndex = 0;

        while (0 == MPGImport.mpg123_read(handle_mpg, Buffer, FrameSize, out done))
        {
            float[] fArray;
            fArray = ByteToFloat(Buffer);

            myClip.SetData(fArray, (importIndex * fArray.Length) / 2);

            importIndex++;
        }

        MPGImport.mpg123_close(handle_mpg);

        print("done loading");
        myClip.name = Path.GetFileName(mPath);
        clips.Add(myClip);
    }
Exemplo n.º 2
0
    public void MP3(string mPath)
    {
        if (mPath.Length != 0)
        {
            MPGImport.mpg123_init();
            handle_mpg = MPGImport.mpg123_new(null, errPtr);
            x          = MPGImport.mpg123_open(handle_mpg, mPath);
            MPGImport.mpg123_getformat(handle_mpg, out rate, out channels, out encoding);
            intRate     = rate.ToInt32();
            intChannels = channels.ToInt32();
            intEncoding = encoding.ToInt32();

            MPGImport.mpg123_id3(handle_mpg, out id3v1, out id3v2);
            MPGImport.mpg123_format_none(handle_mpg);
            MPGImport.mpg123_format(handle_mpg, intRate, intChannels, 208);

            FrameSize = MPGImport.mpg123_outblock(handle_mpg);
            byte[] Buffer = new byte[FrameSize];
            lengthSamples = MPGImport.mpg123_length(handle_mpg);

            myClip = AudioClip.Create(mPath, lengthSamples, intChannels, intRate, false, false);

            int importIndex = 0;

            while (0 == MPGImport.mpg123_read(handle_mpg, Buffer, FrameSize, out done))
            {
                float[] fArray;
                fArray = ByteToFloat(Buffer);

                myClip.SetData(fArray, (importIndex * fArray.Length) / 2);

                importIndex++;
            }

            MPGImport.mpg123_close(handle_mpg);

            audioSource.clip = myClip;
            audioSource.loop = true;
            audioSource.Play();
        }
    }
Exemplo n.º 3
0
    private const double const_1_div_2147483648_ = 1.0 / 2147483648.0; // 32 bit
    #endregion

    public static AudioClip StartImport(string path)
    {
        MPGImport.mpg123_init();
        handle_mpg = MPGImport.mpg123_new(null, errPtr);
        int x = MPGImport.mpg123_open(handle_mpg, path);

        MPGImport.mpg123_getformat(handle_mpg, out rate, out channels, out encoding);
        int intRate     = rate.ToInt32();
        int intChannels = channels.ToInt32();
        int intEncoding = encoding.ToInt32();

        MPGImport.mpg123_id3(handle_mpg, out id3v1, out id3v2);
        MPGImport.mpg123_format_none(handle_mpg);
        MPGImport.mpg123_format(handle_mpg, intRate, intChannels, 208);

        int FrameSize = MPGImport.mpg123_outblock(handle_mpg);

        byte[] Buffer        = new byte[FrameSize];
        int    lengthSamples = MPGImport.mpg123_length(handle_mpg);

        AudioClip myClip = AudioClip.Create(Path.GetFileNameWithoutExtension(path), lengthSamples, intChannels, intRate, false, false);

        int importIndex = 0;

        while (0 == MPGImport.mpg123_read(handle_mpg, Buffer, FrameSize, out done))
        {
            float[] fArray;
            fArray = ByteToFloat(Buffer);

            myClip.SetData(fArray, (importIndex * fArray.Length) / 2);

            importIndex++;
        }

        MPGImport.mpg123_close(handle_mpg);

        return(myClip);
    }
Exemplo n.º 4
0
    public TrackInfo GetTrackInfo(string path)
    {
        MPGImport.mpg123_init();
        handle_mpg = MPGImport.mpg123_new(null, errPtr);
        x          = MPGImport.mpg123_open(handle_mpg, path);
        MPGImport.mpg123_getformat(handle_mpg, out rate, out channels, out encoding);
        intRate     = rate.ToInt32();
        intChannels = channels.ToInt32();
        intEncoding = encoding.ToInt32();

        MPGImport.mpg123_id3(handle_mpg, out id3v1, out id3v2);
        MPGImport.mpg123_format_none(handle_mpg);
        MPGImport.mpg123_format(handle_mpg, intRate, intChannels, 208);

        if (id3v1 != IntPtr.Zero)
        {
            MPGImport.mpg123_id3v1 v1 = (MPGImport.mpg123_id3v1)Marshal.PtrToStructure(id3v1, typeof(MPGImport.mpg123_id3v1));
            return(new TrackInfo
            {
                Album = new String(v1.album),                                               // "Runnin' Wild"
                Artist = new String(v1.artist),                                             // "Airbourne"
                Title = new String(v1.title),                                               // "Stand Up For Rock N Roll"
                Year = new String(v1.year),                                                 // "2007"
                Genre = (v1.genre < GenreText.Length ? GenreText[v1.genre] : string.Empty), // "Rock"
                Comment = new String(v1.comment),                                           // "Comment"
                Tag = new String(v1.tag),                                                   // "Comment"
                Rate = intRate,
                Channels = intChannels,
                Encoding = intEncoding
            });
        }
        MPGImport.mpg123_close(handle_mpg);

        // TODO: ID3v2 support is more complex.
        return(new TrackInfo());
    }
Exemplo n.º 5
0
    public AudioClip StartImport(string mPath)
    {
        MPGImport.mpg123_init();
        handle_mpg = MPGImport.mpg123_new(null, errPtr);
        try
        {
            x = MPGImport.mpg123_open(handle_mpg, mPath);
            MPGImport.mpg123_getformat(handle_mpg, out rate, out channels, out encoding);
            intRate     = rate.ToInt32();
            intChannels = channels.ToInt32();
            intEncoding = encoding.ToInt32();
            MPGImport.mpg123_id3(handle_mpg, out id3v1, out id3v2);
            MPGImport.mpg123_format_none(handle_mpg);
            MPGImport.mpg123_format(handle_mpg, intRate, intChannels, 208);

            string title;
            if (id3v1 != IntPtr.Zero)
            {
                Debug.Log("Getting ID3 info");
                MPGImport.mpg123_id3v1 v1 = (MPGImport.mpg123_id3v1)Marshal.PtrToStructure(id3v1, typeof(MPGImport.mpg123_id3v1));
                title = new String(v1.title);
            }
            else
            {
                title = Path.GetFileNameWithoutExtension(mPath);
            }

            FrameSize = MPGImport.mpg123_outblock(handle_mpg);
            byte[] Buffer = new byte[FrameSize];
            lengthSamples = MPGImport.mpg123_length(handle_mpg);

            Debug.Log("Creating audio clip");
            myClip = AudioClip.Create(title, lengthSamples, intChannels, intRate, false);

            int importIndex = 0;

            while (0 == MPGImport.mpg123_read(handle_mpg, Buffer, FrameSize, out done))
            {
                float[] fArray;
                fArray = ByteToFloat(Buffer);
                float offset = (importIndex * fArray.Length) / 2;
                if (offset > lengthSamples)
                {
                    Debug.LogWarning("[STED] MP3 file " + mPath + " is of an unexpected length and was truncated.");
                    break; // File was reported as shorter than it is. Salvage what we have and return.
                }
                myClip.SetData(fArray, (int)offset);
                importIndex++;
            }
        }
        catch (Exception ex)
        {
            // Attempt to dump any used memory before continuing.
            // TODO: Still holds onto memory when repeatedy failing.
            myClip.UnloadAudioData();
            myClip = null;
            throw ex;
        }
        finally
        {
            MPGImport.mpg123_close(handle_mpg);
        }
        return(myClip);
    }
Exemplo n.º 6
0
    IEnumerator ShowLoadDialogCoroutine()
    {
        // Show a load file dialog and wait for a response from user
        // Load file/folder: file, Initial path: default (Documents), Title: "Load File", submit button text: "Load"
        yield return(FileBrowser.WaitForLoadDialog(false, null, "Load File", "Load"));

        // Dialog is closed
        // Print whether a file is chosen (FileBrowser.Success)
        // and the path to the selected file (FileBrowser.Result) (null, if FileBrowser.Success is false)
        Debug.Log(FileBrowser.Success + " " + FileBrowser.Result);

        if (FileBrowser.Success)
        {
            // If a file was chosen, read its bytes via FileBrowserHelpers
            // Contrary to File.ReadAllBytes, this function works on Android 10+, as well
            mPath = FileBrowser.Result;
            Debug.Log(mPath);

            if (mPath.Length != 0)
            {
                Image o = Instantiate(prefab, transform);
                Debug.Log(mPath);

                //audioSource = (AudioSource)gameObject.GetComponent(typeof(AudioSource));
                //if (audioSource == null) audioSource = (AudioSource)gameObject.AddComponent<AudioSource>();


                MPGImport.mpg123_init();
                handle_mpg = MPGImport.mpg123_new(null, errPtr);
                x          = MPGImport.mpg123_open(handle_mpg, mPath);
                MPGImport.mpg123_getformat(handle_mpg, out rate, out channels, out encoding);
                intRate     = rate.ToInt32();
                intChannels = channels.ToInt32();
                intEncoding = encoding.ToInt32();

                MPGImport.mpg123_id3(handle_mpg, out id3v1, out id3v2);
                MPGImport.mpg123_format_none(handle_mpg);
                MPGImport.mpg123_format(handle_mpg, intRate, intChannels, 208);

                FrameSize = MPGImport.mpg123_outblock(handle_mpg);
                byte[] Buffer = new byte[FrameSize];
                lengthSamples = MPGImport.mpg123_length(handle_mpg);

                myClip = AudioClip.Create(mPath, lengthSamples, intChannels, intRate, false, false);

                int importIndex = 0;

                while (0 == MPGImport.mpg123_read(handle_mpg, Buffer, FrameSize, out done))
                {
                    float[] fArray;
                    fArray = ByteToFloat(Buffer);

                    myClip.SetData(fArray, (importIndex * fArray.Length) / 2);

                    importIndex++;
                }

                MPGImport.mpg123_close(handle_mpg);

                audioSource.clip = myClip;
                audioSource.loop = true;

                //audioSource.Play();
            }
        }
    }