* Display the next frame and play the sound. * \return false if the end of the video is reached. */
| 852 | * \return false if the end of the video is reached. |
| 853 | */ |
| 854 | bool seq_Update() |
| 855 | { |
| 856 | ogg_packet op; |
| 857 | int ret; |
| 858 | int i, j; |
| 859 | float **pcm; |
| 860 | int count, maxsamples; |
| 861 | |
| 862 | /* we want a video and audio frame ready to go at all times. If |
| 863 | we have to buffer incoming, buffer the compressed data (ie, let |
| 864 | ogg do the buffering) */ |
| 865 | if (!videoplaying) |
| 866 | { |
| 867 | debug(LOG_VIDEO, "no movie playing"); |
| 868 | return false; |
| 869 | } |
| 870 | |
| 871 | while (vorbis_p && !audiobuf_ready) |
| 872 | { |
| 873 | /* if there's pending, decoded audio, grab it */ |
| 874 | if ((ret = vorbis_synthesis_pcmout(&videodata.vd, &pcm)) > 0) |
| 875 | { |
| 876 | // we now have float pcm data in pcm |
| 877 | // going to convert that to int pcm in audiobuf |
| 878 | count = audiodata.audiobuf_fill / 2; |
| 879 | maxsamples = (audiodata.audiofd_fragsize - audiodata.audiobuf_fill) / 2 / videodata.vi.channels; |
| 880 | |
| 881 | for (i = 0; i < ret && i < maxsamples; i++) |
| 882 | { |
| 883 | for (j = 0; j < videodata.vi.channels; j++) |
| 884 | { |
| 885 | int val = static_cast<int>(nearbyint(pcm[j][i] * 32767.f)); |
| 886 | |
| 887 | if (val > 32767) |
| 888 | { |
| 889 | val = 32767; |
| 890 | } |
| 891 | else if (val < -32768) |
| 892 | { |
| 893 | val = -32768; |
| 894 | } |
| 895 | audiobuf[count++] = val; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | vorbis_synthesis_read(&videodata.vd, i); |
| 900 | audiodata.audiobuf_fill += i * videodata.vi.channels * 2; |
| 901 | |
| 902 | if (audiodata.audiobuf_fill == audiodata.audiofd_fragsize) |
| 903 | { |
| 904 | audiobuf_ready = true; |
| 905 | } |
| 906 | |
| 907 | if (videodata.vd.granulepos >= 0) |
| 908 | { |
| 909 | audiobuf_granulepos = videodata.vd.granulepos - ret + i; |
| 910 | } |
| 911 | else |
no test coverage detected