{"action":"created","issue":{"url":"https://api.github.com/repos/xmos/lib_mic_array/issues/39","repository_url":"https://api.github.com/repos/xmos/lib_mic_array","labels_url":"https://api.github.com/repos/xmos/lib_mic_array/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/xmos/lib_mic_array/issues/39/comments","events_url":"https://api.github.com/repos/xmos/lib_mic_array/issues/39/events","html_url":"https://github.com/xmos/lib_mic_array/issues/39","id":185469137,"number":39,"title":"mic_array_decimate_to_pcm_4ch() corrupting memory","user":{"login":"astew","id":4711822,"avatar_url":"https://avatars.githubusercontent.com/u/4711822?v=3","gravatar_id":"","url":"https://api.github.com/users/astew","html_url":"https://github.com/astew","followers_url":"https://api.github.com/users/astew/followers","following_url":"https://api.github.com/users/astew/following{/other_user}","gists_url":"https://api.github.com/users/astew/gists{/gist_id}","starred_url":"https://api.github.com/users/astew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astew/subscriptions","organizations_url":"https://api.github.com/users/astew/orgs","repos_url":"https://api.github.com/users/astew/repos","events_url":"https://api.github.com/users/astew/events{/privacy}","received_events_url":"https://api.github.com/users/astew/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-26T18:12:35Z","updated_at":"2016-10-26T20:18:23Z","closed_at":null,"body":"In the project I'm currently working on, I have a task which owns a block of memory. At the beginning of each loop, I zero out this block of memory via `memset()`. I noticed when debugging my project that almost immediately after calling `memset()` (before I wrote anything else to it), part of my memory was no longer zeroed.\r\n\r\nAfter spending a good bit of time drilling down, I believe I've discovered the culprit: `mic_array_decimate_to_pcm_4ch()`.\r\n\r\nThe offending line of code is `decimate_to_pcm_4ch.S` line `826` ( which calls the `SAVE_SAMPLES_NORMAL()` macro). Every time this line is executed, it writes to the next word in my memory block.\r\n\r\nI suspect this may be responsible for a range of problems I've periodically encountered, including data corruption, unexpected runtime exceptions, and sometimes code that just seems to quietly fail. The location at which is writes to memory is consistent with a given image, but small changes in code cause it to write to different places in memory (presumably due to symbol placement)."},"comment":{"url":"https://api.github.com/repos/xmos/lib_mic_array/issues/comments/256464625","html_url":"https://github.com/xmos/lib_mic_array/issues/39#issuecomment-256464625","issue_url":"https://api.github.com/repos/xmos/lib_mic_array/issues/39","id":256464625,"user":{"login":"astew","id":4711822,"avatar_url":"https://avatars.githubusercontent.com/u/4711822?v=3","gravatar_id":"","url":"https://api.github.com/users/astew","html_url":"https://github.com/astew","followers_url":"https://api.github.com/users/astew/followers","following_url":"https://api.github.com/users/astew/following{/other_user}","gists_url":"https://api.github.com/users/astew/gists{/gist_id}","starred_url":"https://api.github.com/users/astew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astew/subscriptions","organizations_url":"https://api.github.com/users/astew/orgs","repos_url":"https://api.github.com/users/astew/repos","events_url":"https://api.github.com/users/astew/events{/privacy}","received_events_url":"https://api.github.com/users/astew/received_events","type":"User","site_admin":false},"created_at":"2016-10-26T20:18:23Z","updated_at":"2016-10-26T20:18:23Z","body":"Okay, so I believe I've solved it.\r\n\r\nNot shown in my previous comment is that `MIC_ARRAY_NUM_MICS`, defined in `mic_array_conf.h` is `3`, because we're only actually using 3 microphones. The frame buffers allocated above rely on `MIC_ARRAY_NUM_MICS` to allocate enough space for the data, which I was not doing.\r\n\r\nThere's still a potential issue here, though. I tried changing my decimator configuration to only use 3 channels. When I did that, my memory block was no longer overwritten with microphone data, but is instead overwritten with zeros.\r\n\r\n`MIC_ARRAY_NUM_MICS` has to be `4`, because `SAVE_SAMPLES_NORMAL `(called at [`decimate_to_pcm_4ch.S:826`](https://github.com/xmos/lib_mic_array/blob/master/lib_mic_array/src/decimate_to_pcm_4ch.S#L826) always does 4 word writes.\r\n\r\nOur work-around will have to be to always request 4 channels, but to only use 3 of them.\r\n\r\nAs a fix, I suggest a run-time assertion when initializing decimators to disallow any fewer than 4 microphones to be used. Clear documentation in the `mic_array.h` comments would also help to avoid others encountering this issue in the future."}}
{"actor":{"display_login":"astew"}}